ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monk
I have a cgi script which has a "a href" tag link on it and below that link a table containing some data. The link is for creating an excel report which will contain the table data on that page.
Now in the background , clicking on that link , it redirects to another script (createReport.pl)and generates the excel report.
Now I want to download that report also , but that is not working.
My cgi script is below :
use CGI; my $cgi = CGI->new (); my $js = <<'JS'; function reportCreate() { var currenturl = document.URL; var url = "https://autoreport.com:8001/cgi-bins/createReport.pl?url="+ +currenturl; window.location.href = url ; return 1; } JS print qq{<script type = "text/javascript">$js</script>}; print $cgi->a({-href=>"javascript:void(0);", -onclick => "reportCreate +();" }, 'Create Report <br>'); print qq{<TABLE BORDER=1><TR BGCOLOR="#D0D0D0"><TH ALIGN=LEFT NOWRAP +>Name}; print qq{</TH>}; ## some Table html code here...please assume print qq{</TABLE>};
Now the above code is working fine. Below I am givnig the createReport.pl script to which the above script redirects. createReoprt.pl is creating the excel sheet report and pushing the content of the table inside it successfully. But I am concerened about the code below that for downloading which is not working.
use Spreadsheet::WriteExcel; use HTML::TableExtract qw(tree); require LWP::UserAgent; my $filename = "/home/user/report.xls"; # The excel generation using Spreasheet # The table extraction as element using TableExtract # All fine till now , and the excel is getting generated # with the desired content. # But this below piece of code is not working, please let me know how + to make it work : open(FILE, "<$filename ") || die "Unable to download file \n"; my @fileholder; binmode FILE; @fileholder = <FILE>; close (FILE); print "Content-Type:application/vnd.ms-excel\n"; print "Content Disposition:attachment;filename=report.xls\n\n"; print @fileholder;
Please help.
|
|---|