Gossamer Forum
Home : Products : Links 2.0 : Discussions :

easy Excel option

Quote Reply
easy Excel option
I've created a quick and easy way to view your database in an excel browser. Hope someone finds this useful.

#!/usr/local/bin/perl -w

use CGI qw(:standard);
use Spreadsheet::WriteExcel;

$header = "Please Wait Loading";

# Open the file with pipe | separated variables
open (PIPEFILE, "/path/to/default.db");

# Create a new Excel file
my $excel = Spreadsheet::WriteExcel->new("/path/to/webserver/default.xls");

# Row and column are zero indexed
my $row = 0;
my $col;

while (<PIPEFILE>) {
chomp;
# Split on single tab
my @Fld = split('\|', $_);
my $token;

$col = 0;
foreach $token (@Fld) {
# Write number or string as necessary
$excel->xl_write($row, $col, $token);
$col++;
}
$row++;
}

print "Content-Type: text/html\n\n\n";
print("<HTML><HEAD><TITLE>Excel View</TITLE><META HTTP-EQUIV=\"REFRESH\" CONTENT=\"2; url=http://www.yourserver.com/default.xls\"></HEAD> <BODY bgcolor=#ffffff><BR><BR><BR> <FONT COLOR=#000000 ><CENTER><H1>$header</H1></CENTER></FONT><BR>");
print("</body></HTML>");

exit;


Quote Reply
Re: easy Excel option In reply to
Cool mod! Although people should be aware that they must have the Spreadsheet Perl module installed in their servers. If not, you can use the app/xls header content type and print the results into a xls file.

You should put the mod in a text file and then upload it into the Resources section of this web site.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: easy Excel option In reply to
So, you would change:

print "Content-Type: text/html\n\n\n";

to:

print "Content-Type: app/xls\n\n\n";

Is that right, AnthroRules?

Many thanks Smile

DT

Quote Reply
Re: easy Excel option In reply to
Yes...That should take the data and put it into an .xls file that you can download.

Regards,

Eliot Lee Wink
http://anthrotech.com/
Quote Reply
Re: easy Excel option In reply to
Thank you very kindly, AnthroRules. Smile

DT

Quote Reply
Re: easy Excel option In reply to
Hi

The error that I get goes like this:

In Reply To:
Can't locate object method "new" via package "Spreadsheet::WriteExcel"
Line 22 looks like this:

my $excel = Spreadsheet::WriteExcel->new("/home/mysite/public_html/excel.xls");

excel.xls is simply a blank document.

I've never used the Spreadsheet module. So, I'm not quite sure what the error is.

What does it mean when it says that it can't locate an object method?

Thanks very much. Smile

DT

Quote Reply
Re: easy Excel option In reply to
It is likely to mean that you don't have Spreadsheet::WriteExcel installed.

shell> perl -MCPAN -e 'install Spreadsheet::WriteExcel'

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: easy Excel option In reply to
Thanks very much, Paul. I'll give it a shot.

DT Smile

Quote Reply
Re: easy Excel option In reply to
I have all required modules installed, yet I receive the following error msg:
Code:
Can't locate object method "xl_write" via package "Spreadsheet::WriteExcel" at w
ww/cgi-bin/myfile.cgi line 27, <PIPEFILE> chunk 1.
Any ideas?


Quote Reply
Re: easy Excel option In reply to
Where can I download the Spreadsheet module?


----------------------
I will rule the world!
Quote Reply
Re: easy Excel option In reply to
http://www.cpan.org


Quote Reply
Re: [gobucs] easy Excel option In reply to
Hi,

Is there away to go "roundtrip" with this?

In other words, take the excel file generated by the mod,
add updates, new data etc., and reupload it through the mod, (preferably with an auto backup of the file being replaced)?

TIA!