| |||||||||||
| |||||||||||
Excel Download Perl CGI Posted by gmeyer (gmeyer), 23 March 2004 Hi Guys,I am having difficulty getting my 'Download to Excel' button to actually pop up a Save As window and download the excel spreadsheet. I am using CGI module to generate the web page and also Spreadhseet::WriteExcel to create the xls file. I need help on getting the following code working please: my $query = new CGI; print $query->header('application/vnd.ms-excel,-attachment=>'path to excel file'); Am I barking up the wrong tree?? Any help appreciated. Gordon Posted by admin (Graham Ellis), 23 March 2004 Something odd with the quotes there, and (I think) a mixture of the two syntaxes for header. Have you tried something likeCode:
Posted by gmeyer (gmeyer), 23 March 2004 Hi Graham,Sorry mistyped in message...my code looks eactly as u have suggested, but Im afraid it doesnt work ![]() If I just have the 'application/vnd.ms-excel' part of the code then it does open excel in the browser. However there is nothing to put in it of course because there is no attachment! Gordon Posted by admin (Graham Ellis), 24 March 2004 What's the rest of your code doing / generating? I think the -attachment option simply sets the name that the file is to be given when it's saved at your local machine and that you need to actually send the content too. Posted by gmeyer (gmeyer), 24 March 2004 Short history of problem:originally there was simply a hyperlink 'Download to Excel' which pointed to report.xls This worked if right clicked and save as..but left click sometimes opens straight in the browser. My idea was to write Perl CGI prog instead so that the user can click a 'Download to Excel' button. Ive tried different code including following: use strict; use CGI qw /:standard /; my $query = new CGI; print $query->header(-type=>"application/vnd.ms-excel",-attachment=>"path/file.xls",-Content_length=>" -s path/file.xls"); open (FH, "path/file.xls"); print $_ while <FH>; close (FH); Posted by admin (Graham Ellis), 25 March 2004 I would tend to use read rather than < ... > to read the file as it will contain binary information, but that's probably just a niceity; it will loop in very odd blocks the way you have it, but I think it will work.Have you tried seting the MIME type for .xls on your server to application/vnd.ms-excel and simply sending a link? This would cut out the Perl program (oops - shouldn't suggest that on the Perl board!). An experiment worth trying anyway as it will help you see if you're looking at server or client side isssues with those "sometimes" issues. I would also try the script out with "application/octet-stream" which should force download to file - again as a tool to help research what you're seeing. Posted by gmeyer (gmeyer), 25 March 2004 Hi Graham,Thanks for the advice. I originally did have a hyperlink to the excel file (not pl prog). I have now found a way of always opening excel when the link is clicked. Unfortunately it involves changing a setting on each of the clients. Oh well they can live with that ![]() FYI http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q162/0/59.asp&NoWebContent=1 Gordon This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |