Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

creating xls files for download

by existem (Sexton)
on Feb 15, 2005 at 15:13 UTC ( #431212=perlquestion: print w/replies, xml ) Need Help??

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

I have to do something i've not done before. I'm creating a system that makes reports and displays them on the screen. It works rather well actually (thanks in part to some helpful people on this forum :) But the next step is including a link to download the report. I want this to be in CSV and XLS format. Can anyone advise me the best way of doing this?

I thought I could create a separate download.cgi script which could then maybe set the content-type to be something other than text/html, which might output to the browser something? Am I on the wrong track here?

Suggestions would be appreciated, thanks as always,

Replies are listed 'Best First'.
Re: creating xls files for download
by dragonchild (Archbishop) on Feb 15, 2005 at 15:22 UTC
    Excel::Template and a content-type of application/

    Note: This has been asked a few times before:

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Re: creating xls files for download
by Jaap (Curate) on Feb 15, 2005 at 15:22 UTC
    You are on the right track. You can use content-type and content-disposition to set the mime type and the filename, respectively. My /etc/mime.types seems to think that application/ is the correct mimetype for excel.
Re: creating xls files for download
by phaylon (Curate) on Feb 15, 2005 at 15:19 UTC
    Have you searched CPAN for excel? An other way would be to publish just the CSV files, Excel should have no problem to open it. Or do you need Excel-specific functions in there?


    Ordinary morality is for ordinary people. -- Aleister Crowley
Re: creating xls files for download
by jcoxen (Deacon) on Feb 15, 2005 at 15:31 UTC
    While I can't speak to the cgi portion of your question, I have created static html pages with links to .xls files. Spreadsheet::WriteExcel works great for that. However, it's not the fastest thing in the world. Since I'm generating my reports and the static html pages that link to them during slack times, that's not an issue for me. With an interactive interface, it may be for you. If you're generating large, multi-tab spreadsheets you might want to consider a less interactive approach like emailing the completed report to the user rather than have them sit there staring at a 'Working...' message for however long it takes to generate the spreadsheets.


Re: creating xls files for download
by jmcnamara (Monsignor) on Feb 15, 2005 at 16:47 UTC
Re: creating xls files for download
by Thilosophy (Curate) on Feb 16, 2005 at 05:22 UTC
    A nice trick you can do here is to make use of the fact that Excel can open HTML files.

    Try this: Make your report in HTML as usual (probably just a bit simpler on the design side), save the source from your browser, rename the file to ".xls" and see how it looks in Excel. Chances are that it looks better than what you could achieve (without a lot of effort) trying to write a CSV or XLS.

    If you like what you see, have your download.cgi serve this HTML file with these headers:

    Content-type: application/ Content-Disposition: attachment; filename=report.xls

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://431212]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2022-08-15 18:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found