[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cgiapp] creating a .csv file...


Franki wrote:
I need to put a link on the DB displays where they can download the data in
csv format (comma seperated values so the winblows newbies get an excel icon
appear when the download it.)

Anyway, I don't want to create the file unless they are gonna use it..
because it will take resources to create a file that might not be used, and
its slowish already.. (need to upgrade the server soon.)

I thought about creating a runmode for the csv that receives the relevant
query data from the runmode that refered to it... and does the query again,
this time printing to file while in the fetchrow loop... then print a
download header and start the download...


I did something almost exactly like this a few weeks ago. Instead of a new run mode I used a parameter on an existing run mode. The logic is like this:

I have a run mode that displays a list of details in an HTML table that happens to look a lot like a spreadsheet display. At the bottom of the page is a hyperlink (could be text or tied to a button or image, your choice) that uses the same URL that brought me to the current run mode but with one parameter different in order to dictate that the output should look like a downloadable excel file instead of a web page. Specify the output header is of type application/ms-excel and specify an attachment with a filename that has an xls extension. It will magically show up as a download to the user without redisplaying the current web page. To set the header I used this:

    my $Output = CGI::header(-type => "application/ms-excel",
			     -attachment => $FileName);

before I added any other text to the $Output string that my run mode returns. Since then I've seen mention in the pod docs that there is a header_props method to CGI::Application that I had missed before. This is probably the more proper way to setup the header.

BTW, you do not have to print to a file, that is a waste of time and resources. Just throw it all into the output string and go.
--

Dan Coutu
Managing Director
Snowy Owl Internet Consulting, LLC
http://www.snowy-owl.com/
Mobile: 603-759-3885
Fax: 603-673-6676



---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.