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;
In reply to Re: Spreadsheet::WriteExcel with CGI
by ChemBoy
in thread Spreadsheet::WriteExcel with CGI
by amt
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |