DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser

 

comments45 comments. Current rating: 3 stars (44 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 3 of 3, other pages: 1 2 [3]
2019-06-09, 05:39:05
anonymous from Russian Federation  
rating
[url= https://furosemide10..furosemide 20 mg tablets[/url] [url= https://metformin850..]metformin for sale[/url] [url= https://viagra25.com/]viagra for women pink pill[/url] [url= https://lasixiv.com/..asix[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://prednisoneta..prednisone 5 mg tablets[/url]
2019-06-09, 07:55:16
anonymous from Russian Federation  
rating
2019-06-09, 08:26:43
anonymous from Russian Federation  
rating
2019-06-09, 11:36:07
anonymous from Russian Federation  
rating
2019-06-09, 11:45:22
anonymous from Russian Federation  
rating
[url= https://metformin850.com/]buy metformin 500mg[/url] [url= https://trazodone100..done[/url] [url= https://viagra25.com..agra[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://suhagra50.com/]generic suhagra[/url] [url= https://furosemide10..furosemide 20 mg tablets[/url] [url= https://prednisonetab.com/]buy prednisone no prescription[/url] [url= https://prednisolone..lone[/url] [url= https://ventolin100.../]ventolin inhaler[/url] [url= https://lasixiv.com/]buy lasix online no prescription[/url]
2019-06-09, 12:05:00
anonymous from Russian Federation  
rating
2019-06-09, 12:31:20
anonymous from Russian Federation  
rating
[url= https://antabusedisu..m.com/]buy antabuse uk[/url] [url= https://furosemide10..m/]generic no prescription cheap furosemoide[/url] [url= https://lasixiv.com/]buy lasix water pill[/url] [url= https://metformin850..]metformin hcl[/url] [url= https://prednisonetab.com/]buy cheap prednisone[/url]
2019-06-09, 14:44:18
anonymous from Russian Federation  
rating
[url= https://viagra25.com..agra[/url] [url= https://metformin850..]metformin 850[/url] [url= https://prednisolone..lone[/url] [url= https://lasixiv.com/]buy lasix without a doctor's prescription[/url] [url= https://ventolin100.../]ventolin inhaler[/url] [url= https://antabusedisu..m.com/]buy antebuse online 250 mg uk[/url] [url= https://furosemide10..furosemide online no prescription[/url] [url= https://suhagra50.com/]buy suhagra online[/url] [url= https://trazodone100..om/]online trazodone[/url] [url= https://prednisoneta..sone[/url]
2019-06-09, 15:33:23
anonymous from Russian Federation  
rating
[url= https://prednisolone4.com/]buy prednisolone[/url]
2019-06-09, 15:53:32
anonymous from Russian Federation  
rating
[url= https://prednisolone..com/]where can i buy prednisolone in the uk[/url]
2019-06-09, 17:27:29
anonymous from Russian Federation  
rating
2019-06-09, 20:46:25
anonymous from Russian Federation  
rating
2019-06-09, 23:01:26
anonymous from Russian Federation  
rating
[url= https://ventolin100.../]ventolin without a prescription[/url]
2019-06-10, 10:37:38
anonymous from Russian Federation  
rating
[url= https://lasixiv.com/]buy cheap lasix[/url] [url= https://metformin850..]metformin 850[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://furosemide10..furosemide tab 40mg[/url] [url= https://prednisolone4.com/]buy predislone tablets[/url] [url= https://trazodone100..com/]order trazodone online[/url] [url= https://suhagra50.com/]buy suhagra[/url] [url= https://prednisoneta..om/]canine prednisone 5mg no prescription[/url] [url= https://viagra25.com/]low cost viagra[/url] [url= https://ventolin100.com/]buy ventolin inhaler online[/url]
2019-06-10, 13:55:22
anonymous from Russian Federation  
rating
[url= https://prednisoneta..com/]order prednisone with mastercard debit[/url] [url= https://suhagra50.com/]suhagra generic[/url] [url= https://viagra25.com/]price of viagra per pill[/url] [url= https://antabusedisu..m.com/]buy antabuse uk[/url] [url= https://furosemide10..furosemide tab 40mg[/url] [url= https://trazodone100..]trazodone hydrochloride 100 mg[/url] [url= https://ventolin100.../]ventolin nebules[/url] [url= https://lasixiv.com/]lasix water pill 20 mg buy no prescription[/url] [url= https://metformin850..]metformin on line[/url] [url= https://prednisolone..ednisolone drug[/url]
You are on page 3 of 3, other pages: 1 2 [3]

 

 

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: