DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser

 

comments90 comments. Current rating: 2 stars (89 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 6 of 6, other pages: 1 2 3 4 5 [6]
2019-06-28, 04:21:07
anonymous from Russian Federation  
rating
2019-06-28, 06:36:39
anonymous from Russian Federation  
rating
2019-06-28, 06:58:10
anonymous from Russian Federation  
rating
[url= https://allopurinolz..inol[/url] [url= https://cafergot100.../]cafergot pills[/url] [url= https://sildalis120...m/]generic sildalis[/url] [url= https://vardenafilbuy.com/]buy vardenafil canada[/url] [url= https://buydiflucan.com/]buy diflucan[/url] [url= https://tetracycline..com/]order tetracycline online without prescription[/url] [url= https://generictadal..]tadalafil 20mg[/url] [url= https://zoviraxacycl..r.com/]buy acyclovir 400 mg[/url] [url= https://atarax10.com/]generic for atarax[/url] [url= https://levitrasale.com/]buy levitra[/url]
2019-06-28, 07:51:50
anonymous from Russian Federation  
rating
[url= https://buydiflucan.com/]buy fluconazole no rx[/url] [url= https://vardenafilbu..vardenafil generic levitra[/url] [url= https://wellbutrin300.com/]buy wellbutrin[/url] [url= https://generictadal..]tadalafil generic[/url]
2019-06-28, 08:00:46
anonymous from Russian Federation  
rating
2019-06-28, 08:28:28
anonymous from Russian Federation  
rating
2019-06-28, 08:46:19
anonymous from Russian Federation  
rating
[url= https://levitrasale.com/]buy generic levitra[/url]
2019-06-28, 11:01:40
anonymous from Russian Federation  
rating
[url= https://cafergot100.../]cafergot online[/url] [url= https://lisinoprilbu..lisinopril tabs[/url] [url= https://xenical120mg..m/]xenical canada[/url] [url= https://tetracycline..5.com/]buy tetracycline antibiotics[/url] [url= https://generictadal..]tadalafil india 20mg[/url] [url= https://atarax10.com/]atarax hydrochloride[/url] [url= https://hydrochlorot..rothiazide 25 mg price[/url] [url= https://femaleviagra..om/]female viagra[/url]
2019-06-28, 11:01:44
anonymous from Russian Federation  
rating
[url= https://vardenafilbu..vardenafil best price[/url] [url= https://tetracycline..5.com/]buy cheap tetracycline[/url] [url= https://atenolol25.c../]tenormin 50mg[/url]
2019-06-28, 11:36:18
anonymous from Russian Federation  
rating
[url= https://zoviraxacycl..]acyclovir over the counter[/url]
2019-06-28, 12:43:41
anonymous from Russian Federation  
rating
2019-06-28, 12:50:26
anonymous from Russian Federation  
rating
2019-06-28, 13:06:00
anonymous from Russian Federation  
rating
2019-06-28, 17:00:57
anonymous from Russian Federation  
rating
2019-06-28, 17:20:03
anonymous from Russian Federation  
rating
[url= https://buydiflucan.com/]buy diflucan without a prescription[/url]
You are on page 6 of 6, other pages: 1 2 3 4 5 [6]

 

 

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: