in reply to Force Download to a .xls file


Try the following Content-type and see if it gives better results.

If the program is running on Windows then make sure to binmode the file streams. This may be what is causing the file corruption.

#!/usr/bin/perl -w use strict; my $filename ="../somepath/test.xls"; print "Content-type: application/vnd.ms-excel\n"; print "Content-Disposition: attachment; filename=$filename\n"; print "\n"; open TMP, $filename or die "Error message here: $!\n"; binmode TMP; binmode STDOUT; print <TMP>;

--
John.

Replies are listed 'Best First'.
Re^2: Force Download to a .xls file
by Andre_br (Pilgrim) on Jan 04, 2005 at 05:04 UTC
    Hey John!

    It's a great honour to talk to you. Your Spreadsheet::WriteExcel is just unbelievable. It is being of huge help with the site I´m working on right now - this one is for me, not for a client. You´ve done a great job, congratulations!

    In fact, your binmode tip was precise. It´s working just fine now. Thanks!

    The only thing that´s not too beautifull for the user is that when the dialog box appears, it shows: "Downloading the file: export.cgi?action=3. Do you wish to open it or save it?". Is there any way to skip that dialog and go straight to the window 'Save as'? Any hacks to do it?

    In fact, the browser is correct; but he´s showing the secret of the magic...lghs

    Take care, John!

    André

      >> Is there any way to skip that dialog and go straight to the window 'Save as'? Any hacks to do it?

      honestly, would you want your browser to save files unasked?
      for the naming issue, you could return a redirection header to the excel-file instead of printing the files contents. that way the name would be displayed correctly.