DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser

 

comments162 comments. Current rating: 2 stars (159 votes). Leave comments and/ or rate it.

Question:

I need to have my web site generate an Excel worksheet on the fly (a database export) and send it to the user's webbrowser. How can I do that?

Answer:

The following assumes that you export a simple sheet containing strings and numbers, no formulas.

In this case, you can generate a CSV file (comma separated values) and set the mime type to applicatioon/octet-stream.

If you perl script is called as /cgi-bin/exportcsv.pl then the downloaded file will by default be named

exportcsv.pl.xls (using alternative mime type application/vnd.ms-excel)

To suggest a specific file name (other than the script name, use the Content-Disposition header field. This field allows you to provide other information as well, e.g.

- creation-date
- modification-date
- read-date
- size

Note:
The size parameter indicates just an approximate size of the file in octets. It does not have to be the exact size. This information can be used by the client software (web browser) to pre-allocate space before attempting to store the file, or to determine whether enough space exists.

For the full syntax, see RFC 2183

# alternative 1:
# sending a file simply as an Excel
print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";

# alternative 2:
# sending a CSV file and suggesting 'users.csv' as the file name
print "Content-type: application/octet-stream\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";

# now dump the data
# all values are enclosed by " in case the 
# strings contain a comma
# this dumps 2 rows with 2 columns each
print '"1","Test, first one"' . "\n";
print '"2","Test, last one"' . "\n";


Content-type: text/html

Comments:

You are on page 11 of 11, other pages: 1 2 3 8 9 10 [11]
2019-07-31, 11:09:37
mitwisewrigpowermitwise  

Do you need a financial help? Are you in any financial crisis or do you need funds to start up your own business? Do you need funds to settle your debt or pay off your bills or start a good business? Do you have a low credit score and you are finding it hard to obtain capital services from local banks and other financial institutes? Here is your chance to obtain a financial services from our company. We offer the following finance to individuals-
*Commercial finance
*Personal finance
*Business finance
*Construction finance
*Business finance And many More:
and many more at 2% interest rate;
Contact Us Via Email:bullsindia187@gmail.com
This image was also posted here:
Getting started with perl and mysql
How to install DBD for mysql using CPAN



Keywords:
2019-10-22, 11:37:10
anonymous from Ukraine  
rating
chase personal loan [url= https://personalloan..com/]wells fargo personal loan credit requirements[/url] marcus personal loan reviews <a href=' https://personalloan..'>wells fargo personal loan credit requirements</a> personal loan 600 credit score
2019-10-23, 12:07:28
anonymous from Ukraine  
rating
installment loans no credit check direct lenders only [url= https://installmentl..om/]direct lenders for installment loans[/url] installment loans <a href=' https://installmentl..;christmas installment loans</a> online installment loans for bad credit
You are on page 11 of 11, other pages: 1 2 3 8 9 10 [11]

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: