Link to home
Start Free TrialLog in
Avatar of nivo_Z
nivo_Z

asked on

Perl Spreadsheet::WriteExcel : Output to browser - Always opens empty

HI,
I'm writing a Perl based WEB application and I want to display Excel spreadsheet with data in the browser.
When I run the below example an Excel spreadsheet opens in the browser (I'm using IE 5.5, Windows 2000) but it is empty.
No matter what I tried, it always opens empty.
What is the problem?
Also, what is the meaning of the last line in the example description ("This can be useful for CGIs which have a Content-type of application/vnd.ms-excel") ???

Thanks.
 
Following is the description and the example:

2.4.6 Spreadsheet::WriteExcel Example: Output to browser
You can redirect the Spreadsheet::WriteExcel output to STDOUT using the special Perl filehandle "-". This can be useful for CGIs which have a Content-type of application/vnd.ms-excel:


    #!/usr/bin/perl -w


    use strict;
    use Spreadsheet::WriteExcel;
   
    print "Content-type: application/vnd.ms-excel\n\n";
   
    my $workbook = Spreadsheet::WriteExcel->new("-");
    $workbook->write(0, 0, "Hi Excel!");
Avatar of Duositex
Duositex

The author is simply saying that the filehand "-" is useful when trying to direct output from a perl script that delivers a content type of "application/vnd.ms-excel"  Basically the content type is what tells your browser that the information you're sending it has a purpose, and that it should be displayed in a certain manner.  In this case they're simply pointing out that you can output the result of the SpreadSheet:WriteExcel routine to the browser in this manner.  Why doesn't it work?  I have no idea.  It seems to me that you may not have the required module to make the function run correctly.  Your browser gets the content-type segment, and opens its Excel spreadsheet viewer before your CGI reports the error that it doesn't have the module in place to actually input data into the spreadsheet.  Check with your sys admin about installing perl modules.
Avatar of nivo_Z

ASKER

The thing is that when I don't direct the output to the browser and instead I create a spreadsheet on the local drive it works. I managed to create a spreadsheet and display the data successfully.
But this is a limitation because I want to allow access from any machine.
So, I guess that I have the required module.
This is *possibly* due to a permissions issue.

Spreadsheet::WriteExcel needs to open a temporary file to operate. Returning a blank spreadsheet is a known symptom of IO::File not being able to open the temporary file for writing.

How should you proceed? Try writing a perl script which opens a file wherever your %TEMP is set to. Get it to put some text in the file. Run the script under mod_perl exactly as you do this Excel script. See if the file in %TEMP actually exists and contains what it should. If not, you have a permissions issue.
Avatar of nivo_Z

ASKER

Problem found!

When I used:
    $worksheet->write(0, 0, "Hi Excel!");
Instead of:
    $workbook->write(0, 0, "Hi Excel!");
It worked!

ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial