display Excel file in browser?

B

Bing Du

Greetings,

I've used Spreadsheet::WriteExcel to generate a spreadsheet. Now I need
this spreadsheet to be viewable in web browsers. I can _not_ put any
files under the web server document root directory due to the privilege
restrictions. So this has failed my idea of creating a link on the web
page and making the link point to the spreadsheet.

The best place for me to store the sheet is in the /tmp directory. If I
use the following code to load my.xls into $bindata, how can I display
$bindata in its original spreadsheet format on the web?

======
$spreadsheet = "/tmp/my.xls";
open(F,$spreadsheet);
read(F,$bindata,-s F);
close(F);
======

I've checked Spreadsheet::parseExcel. But it's not what I want because
I don't want to extract information from my.xls.

Appreciate any ideas in advance.

Bing
 
R

Richard Morse

Bing Du <[email protected]> said:
Greetings,

I've used Spreadsheet::WriteExcel to generate a spreadsheet. Now I need
this spreadsheet to be viewable in web browsers. I can _not_ put any
files under the web server document root directory due to the privilege
restrictions. So this has failed my idea of creating a link on the web
page and making the link point to the spreadsheet.

The best place for me to store the sheet is in the /tmp directory. If I
use the following code to load my.xls into $bindata, how can I display
$bindata in its original spreadsheet format on the web?

======
$spreadsheet = "/tmp/my.xls";
open(F,$spreadsheet);
read(F,$bindata,-s F);
close(F);
======

I've checked Spreadsheet::parseExcel. But it's not what I want because
I don't want to extract information from my.xls.

Appreciate any ideas in advance.

This has very little to do with Perl.

However.

In order to make anything available over the web, you need to somehow
get it into the web server's namespace. You have two options:

1) change permissions (perhaps on a subdirectory?) so that your script
can save data into a directory that your web server can serve from

2) write a cgi, which accepts some kind of key for which file to serve,
and have it open the file and reprint it to the web browser.

Please note that 2 will cause all kinds of security issues, unless you
are _very_ careful in how you create it.

If you are using Spreadsheet::WriteExcel to create the excel spreadsheet
based on a web query, and you want to return the spreadsheet to a
browser right after creating it, you might try creating the spreadsheet
as a temp file (use File::Temp), then seek-ing to the start of the file,
then printing (with binmode) the file back to the browser.

HTH,
Ricky
 
J

James Willmore

On Wed, 07 Apr 2004 16:11:16 -0400, Richard Morse wrote:

[ ... ]
1) change permissions (perhaps on a subdirectory?) so that your script
can save data into a directory that your web server can serve from

2) write a cgi, which accepts some kind of key for which file to serve,
and have it open the file and reprint it to the web browser.

Please note that 2 will cause all kinds of security issues, unless you
are _very_ careful in how you create it.

If you are using Spreadsheet::WriteExcel to create the excel spreadsheet
based on a web query, and you want to return the spreadsheet to a
browser right after creating it, you might try creating the spreadsheet
as a temp file (use File::Temp), then seek-ing to the start of the file,
then printing (with binmode) the file back to the browser.

The most important part of writing a CGI script to deliver an Excel file
to the browser is the Content-type header.

Information on this *should* be available by using Google :)

HTH

Jim
 
J

John McNamara

Bing Du said:
I've used Spreadsheet::WriteExcel to generate a spreadsheet. Now I
need this spreadsheet to be viewable in web browsers.
...

If I use the following code to load my.xls into $bindata, how can
I display $bindata in its original spreadsheet format on the web?


In the examples directory of the Spreadsheet::WriteExcel distro there
is a program called cgi.pl that shows how to stream an Excel file to a
browser.

The Content-type/Content-Disposition headers in the program will also
work if you wish to stream an existing file.

John.
--
 
B

Bing Du

Thanks so much, folks, for the heads-up. The clues you all provided are
very important and helpful to me.

Bing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,834
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top