MikeGerard has asked for the wisdom of the Perl Monks concerning the following question:

Trying to debug Perl code to create and write an Excel file. My code worked for years, but stopped working a while back. Most often I read that I should use the module Excel::Writer::XLSX, but my ISP on whose system the code runs refuses to include this (for reasons of security, they say). The code which used to work, should create the excel file in a file with the name specified by the attachment name and put into the downloads directory

my $attachment_name = $start_hour . "_" . $hour_count; print $cgi->header(-type=>"application/vnd.ms-excel", -attachment=>"$attachment_name.xls"); print $cgi->start_html(-title=>"Exported Excel results"); # Write the data print $cgi->end_html;</

The data is no longer written into a created Excel file

2024-08-13 Athanasius fixed leading code tag.

Replies are listed 'Best First'.
Re: Excel file in perl program
by talexb (Chancellor) on Aug 13, 2024 at 13:17 UTC

    If you'd previewed your post, you would have seen that the code segment didn't come through correctly. I'm guessing it should have look like this:

      my $attachment_name = $start_hour . "_" . $hour_count; print $cgi->header(-type=>"application/vnd.ms-excel", -attachment=>"$attachment_name.xls"); print $cgi->start_html( -title=>"Exported Excel results"); # Write the data print $cgi->end_html;
    It's a little difficult to figure out what the problem is without more information, but it sounds like this solution used to work, but is now failing. Apart from the missing file, do you have any error logs to tell us about? Does the code still compile? Are you using something other than Excel::Writer::XLSX to create the file? Are you using strict and warnings?

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Re: Excel file in perl program
by soonix (Chancellor) on Aug 13, 2024 at 13:59 UTC
    Is the
    # Write the data
    (a) verbatim from your program, or is it (b) just a placeholder for the code to, umm..., write the data? It looks to me that the code to actually write the data is either (a) missing, or (b) doing something wrong.
Re: Excel file in perl program
by GrandFather (Saint) on Aug 13, 2024 at 21:38 UTC

    When you say "write an Excel file" do you mean create and write to an excel file on your local machine, or do you mean show the existing contents of an excel file in a web page, or are you wanting to generate an excel file on a server to be delivered to a client's browser.? Your sample code implies the latter, but maybe you want to do something altogether different.

    Why don't you show us the code that used to work?

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond