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

How do I open an excel csv file within perl? I use an IE7 where perl is running from unix (part of the network).

Tried:
print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachement; filename=test.xls\n\n";
print $excel;

This opens the excel application with the csv file, except that the csv was not properly formatted according to the comma. One line, including the commas, goes to one cell. If you open the csv file from windows, it is correctly formatted.

Thanks...Ichabod

Replies are listed 'Best First'.
Re: Excel csv with Perl
by atemon (Chaplain) on Sep 18, 2007 at 02:58 UTC

    Content-type application/vnd.ms-excel is used when we send the real excel sheet like one created with Spreadsheet::WriteExcel. If you are sending CSV content, try using "text/csv" as content-type.

    print "Content-type: text/csv\n"; #Changed content-type to CSV print "Content-Disposition: attachement; filename=test.xls\n\n"; print $excel;
    Hope this works.

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

      No effect. Still using excel but one record is still in one cell.

      Thanks...
Re: Excel csv with Perl
by n8g (Sexton) on Sep 18, 2007 at 02:35 UTC
    It might help to see some sample output of the $excel variable?
      Sample of one record as follows:

      ,XXX,YYY,terryc ,ZZZZZ,Palm Road,9 ,TTTT,UUU ,-3.01,-0.30,0.00,0.00,0.00,0.00,-0.30,1,SSS, ,RRR, ,QQQQQ , , , , ,33318 ,20040113,7711,

      Thanks...
Re: Excel csv with Perl
by SFLEX (Chaplain) on Sep 18, 2007 at 09:47 UTC
    you may need to set STDOUT to binary mode.
    binmode STDOUT; print "Content-type: application/vnd.ms-excel\n"; print "Content-Disposition: attachement; filename=test.xls\n\n"; print $excel;
      No effect. Perl is run under unix, so it should have no effect.

      Thanks...
        If you still have problems, try a module to phrase the Excel file.

        "Note: An Excel file is comprised of binary data. binmode"
Re: Excel csv with Perl
by ichabod (Novice) on Sep 21, 2007 at 01:28 UTC
    Folks...

    Thanks to all. Found the solution. Just change the test.xls to test.csv and it is formatting the csv correctly.