Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Display Report Using Excel

by tstock (Curate)
on Jul 07, 2004 at 02:51 UTC ( #372254=note: print w/ replies, xml ) Need Help??


in reply to Display Report Using Excel

If you are trying to make output from a CGI open in excel, you could output a CSV (comma separated values) file, or use Spreadsheet::WriteExcel to output an excel file.

Remember to use use Content-type: application/vnd.ms-excel (or text/x-csv) instead of text/html in your CGI. You might also have to name your cgi .csv or .xls for braindead IE to work properly, since a lot of times it doesn' respect the Content-Disposition filename correctly. Sample code -

#! /usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect( @connect_param ); my $data = $dbh->selectall_arrayref( 'SELECT * FROM country_info' ); print "Content-Type: text/x-csv\n\n"; for (@$data) { print join ",", map { "\"$_\"" } @$_; print "\n"; }

Tiago


Comment on Re: Display Report Using Excel
Download Code
Re^2: Display Report Using Excel
by neeraj (Scribe) on Jul 07, 2004 at 05:39 UTC
    Use Content-type - application-octet-stream.
    #! /usr/bin/perl use strict; use warnings; use DBI; use CGI; my $q = new CGI; my $dbh = DBI->connect( @connect_param ); my $data = $dbh->selectall_arrayref( 'SELECT * FROM country_info' ); print $q->header('Content-type=application/octet-stream;name="data.csv +"'); for (@$data) { print join ",", map { "\"$_\"" } @$_; print "\n"; }
    Neeraj

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://372254]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2014-12-29 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (188 votes), past polls