in reply to Spreadsheet::WriteExcel with CGI
It may not be the cleanest of solutions, but at the moment we do what you're doing with a temp file: create the .XLS file in some random location, then read it back into memory (in the same script) and print it to the client (then, presumably, delete the temp file). This keeps everything in one process, so you can report errors directly to the client (and not bother forking), and also lets you defer printing the headers until you know more about your output (the size, of course, but also if there were any errors as you fetched the data).
That is:
use File::Temp 'tempfile'; use CGI 'header'; my ($fh,$filename) = tempfile(); my $workbook = Spreadsheet::WriteExcel->new($filename); do_stuff($workbook); $fh->seek(0,0); my $data; my $size = -z $filename; $size== $fh->read($data,$size) or bail_the_heck_out(); #CGI::Carp migh +t help print header( -type=>"application/vnd.ms-excel", -content_length=>$size, -attachment=>$file, # assuming you set that elsewhere ), $data;
If God had meant us to fly, he would *never* have given us the railroads.
--Michael Flanders
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Spreadsheet::WriteExcel with CGI
by amt (Monk) on Dec 09, 2005 at 15:56 UTC | |
by ChemBoy (Priest) on Dec 11, 2005 at 17:43 UTC |
In Section
Seekers of Perl Wisdom