DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser


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


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?


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/ then the downloaded file will by default be named (using alternative mime type application/

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

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/\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


You are on page 14 of 14, other pages: 1 2 3 11 12 13 [14]
2019-07-12, 02:37:45
anonymous from Ukraine  
cheap canadian pharmacy online [url=]best canadian online pharmacy reviews[/url] legitimate canadian online pharmacy <a href=' http://canadianonli..#'>best canadian online pharmacy reviews</a> canadian online pharmacy reviews
2019-07-12, 14:08:48
anonymous from Ukraine  
generic viagra online canadian pharmacy [url= http://canadianonli../]canadian online pharmacy reviews[/url] online canadian pharmacy <a href=' http://canadianonli..</a> best online canadian pharmacy review
2019-07-13, 10:15:53
anonymous from Ukraine  
best online canadian pharmacy review [url=]best online canadian pharmacy[/url] canadian online pharmacy viagra <a href=' http://canadianonli..t;canadian online pharmacy viagra</a> viagra online
2019-07-13, 13:07:42
anonymous from Ukraine  
canadian pharmacy online cialis [url=]brand viagra online canadian pharmacy[/url] visit this page <a href=' http://canadianonli..'>brand viagra online canadian pharmacy</a> canadian online pharmacy cialis
2019-07-13, 14:59:22
anonymous from Ukraine  
best canadian pharmacy online [url= http://canadianonli..]reputable canadian online pharmacy[/url] canadian online pharmacy reviews <a href=' http://canadianonli..#'>best canadian online pharmacy</a> legitimate canadian online pharmacy
You are on page 14 of 14, other pages: 1 2 3 11 12 13 [14]



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: