http://qs321.pair.com?node_id=372254


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