Streaming output of Spreadsheet::WriteExcel

169 views
Skip to first unread message

rmeichhorn

unread,
May 25, 2009, 11:06:59 PM5/25/09
to Spreadsheet::WriteExcel
Hi All,

I have created a web based reporting system, which uses mod_perl and
Spreadsheet::WriteExcel to output an xls file to the user who can then
save it to their PC.

I have it working nicely, but have come across one little thing which
would make it better for my end users.

At the moment when a user requests a report which creates a large
spreadsheet, the user has to wait for about 15-30 seconds, before the
browser will prompt for a location to download.

This is due to nothing being written to the filehandle which is used
to create the spreadsheet, until the close() statement is executed. I
fully expected this behaviour as I would imagine you can't output
anything until the worksheet has been built.

I have tried flushing the headers to the browser. That doesn't work
as the browser will not prompt for a download location until at least
some of the file has started to come down. I have tested this by
outputting some data after the header, and it worked. Unfortunately
that corrupts the XLS file.

What I would like is some sort of flush method, which will write the
headers of the XLS file out. It only needs to be a few bytes. I just
need something to get the browser to prompt to save. Once the user
hits save they can go do something else in the browser again, and let
the browser's download manager take over.

Not knowing anything about the structure of the XLS file, it this at
all possible?

Cheers,
Richard.

jmcn...@cpan.org

unread,
May 28, 2009, 4:20:39 PM5/28/09
to Spreadsheet::WriteExcel


On May 26, 4:06 am, rmeichhorn <rmeichh...@gmail.com> wrote:
> What I would like is some sort of flush method, which will write the
> headers of the XLS file out. It only needs to be a few bytes. I just
> need something to get the browser to prompt to save. Once the user
> hits save they can go do something else in the browser again, and let
> the browser's download manager take over.
>
> Not knowing anything about the structure of the XLS file, it this at
> all possible?


Hi Richard,

An Excel file is a binary file within a binary file. It contains
several interlinked checksums and changing even one byte can cause it
to become corrupted.

Nevertheless, you could send the first 8 bytes (see below) which
identify the file and which don't change to the browser, then write
the Excel data to a file and when it is finished send the rest of the
data minus the first 8 bytes.

cfd0 e011 b1a1 e11a

However, I'd imagine that there are more elegant Html/Javascript or
server side solutions that you could implement such as having an
intermediate page telling the user that the file was being generated,
and them streaming it when it is ready.

John.
--
Reply all
Reply to author
Forward
0 new messages