DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser

 

comments232 comments. Current rating: 2 stars (229 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";


Comments:

You are on page 4 of 16, other pages: 1 2 3 [4] 5 6 7 13 14 15 16
2019-06-10, 17:32:06
anonymous from Russian Federation  
rating
[url= https://trazodone100.com/]buy trazodone online[/url] [url= https://viagra25.com..agra[/url] [url= https://lasixiv.com/]vip medications buy lasix without prescription[/url] [url= https://prednisolone4.com/]buy cheap prednisolone[/url] [url= https://suhagra50.com/]generic suhagra[/url] [url= https://prednisoneta..prednisone tablets[/url] [url= https://furosemide10..furosemide 20mg[/url] [url= https://metformin850..]metformin online no prescription[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://ventolin100.../]ventolin no prescription[/url]
2019-06-10, 17:57:11
anonymous from Russian Federation  
rating
[url= https://ventolin100...om/]athsma inhalers no prescription[/url] [url= https://suhagra50.com/]generic suhagra[/url] [url= https://prednisolone..om/]buying prednisoline tablets[/url] [url= https://metformin850.com/]buy metformin[/url] [url= https://lasixiv.com/..asix[/url]
2019-06-10, 17:58:20
anonymous from Russian Federation  
rating
[url= https://antabusedisu../]antabuse disulfiram[/url]
2019-06-10, 20:05:47
anonymous from Russian Federation  
rating
2019-06-10, 23:22:07
anonymous from Russian Federation  
rating
[url= https://prednisoneta..om/]indian prednisone without prescription[/url]
2019-06-11, 05:06:59
anonymous from Russian Federation  
rating
[url= https://furosemide10..furosemide 40 mg tablets online[/url] [url= https://prednisolone..om/]buying prednisoline tablets[/url] [url= https://viagra25.com/]viagra 100mg[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://prednisoneta..sone[/url] [url= https://metformin850..]metformin er 500 mg[/url] [url= https://trazodone100.com/]buy trazadone non generic on line without a prescription[/url] [url= https://lasixiv.com/..asix[/url] [url= https://ventolin100...olin[/url] [url= https://suhagra50.com/]buy suhagra online[/url]
2019-06-14, 09:54:25
anonymous from Russian Federation  
rating
[url= https://viagra25.com/]viagra pills 100 mg[/url]
2019-06-14, 14:19:03
anonymous from Russian Federation  
rating
[url= https://furosemide10..mide[/url] [url= https://prednisolone..ednisolone uk[/url] [url= https://suhagra50.com/]buy suhagra[/url] [url= https://trazodone100.com/]buy trazodone online[/url] [url= https://ventolin100.com/]buy ventolin online[/url] [url= https://metformin850.com/]buy metformin without a proscription[/url] [url= https://prednisoneta..com/]where to buy prednisone tablets[/url] [url= https://viagra25.com..agra[/url] [url= https://antabusedisu../]antabuse disulfiram[/url] [url= https://lasixiv.com/]vip medications buy lasix without prescription[/url]
2019-06-14, 17:48:48
anonymous from Russian Federation  
rating
2019-06-14, 18:09:16
anonymous from Russian Federation  
rating
2019-06-14, 19:48:25
anonymous from Russian Federation  
rating
2019-06-27, 11:52:19
anonymous from Russian Federation  
rating
2019-06-27, 15:20:16
anonymous from Russian Federation  
rating
2019-06-27, 15:25:02
anonymous from Russian Federation  
rating
[url= https://sildalis120.../]sildalis without prescription[/url] [url= https://sildenafil10..sildenafil otc[/url] [url= https://femaleviagra..om/]female viagra[/url]
2019-06-27, 15:46:43
anonymous from Russian Federation  
rating
You are on page 4 of 16, other pages: 1 2 3 [4] 5 6 7 13 14 15 16

 

 

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: