DelphiFAQ Home Search:

Perl script on web server sends Excel file to browser

 

comments60 comments. Current rating: 3 stars (59 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 4 of 4, other pages: 1 2 3 [4]
2020-09-13, 16:30:05
anonymous from Germany  
rating
viagra achat en pharmacie

[url= https://viagiowow.com/]viagra dosage cialis[/url]
<a href=' https://viagiowow.com/'>il viagra fa male al cuor</a>

viagra testpackung kaufen
2020-09-13, 17:23:17
anonymous from Germany  
rating
order viagra and cialis

[url= https://viagiowow.com/]buy viagra[/url]
<a href=' https://viagiowow.com/'>can u take viagra with duodart</a>

viagra 50 mg prices
2020-09-13, 17:46:58
anonymous from Germany  
rating
viagra do i need prescription

[url= https://viagiowow.com/]generic viagra[/url]
<a href=' https://viagiowow.co../'>much does viagra cost india</a>

generic viagra manufacturer
2020-09-13, 19:46:31
anonymous from Germany  
rating
retail price of 100 mg viagra

[url= https://viagiowow.com/]buy cheap viagra pills online[/url]
<a href=' https://viagiowow.co..>online viagra canada no</a>

do viagra pills get old
2020-09-13, 22:01:19
anonymous from Germany  
rating
best buy on viagra

[url= https://viagiowow.com/]online genetic viagra store[/url]
<a href=' https://viagiowow.co..>viagra en vente franc</a>

viagra richtig einnehmen
2020-09-14, 00:16:49
anonymous from Germany  
rating
cat costa viagra

[url= https://viagiowow.com/]buying viagra on line[/url]
<a href=' https://viagiowow.com/'>buy generic viagra</a>

cadre de viagra brand
2020-09-14, 02:01:46
anonymous from Germany  
rating
click now best viagra price

[url= https://viagiowow.com/]buy viagra online[/url]
<a href=' https://viagiowow.co..>viagra cheap</a>

where can one purchase viagra
2020-09-14, 04:36:17
anonymous from Germany  
rating
i use it viagra costs

[url= https://viagiowow.com/]viagra online[/url]
<a href=' https://viagiowow.co..>viagra cheap</a>

viagra hardon
2020-09-14, 09:04:26
anonymous from Germany  
rating
does cialis work for bph

[url= https://cialisverygo..n.com/]buy cialis online[/url]
<a href=' https://cialisverygo..m/'>buy generic cialis</a>

mejor web para comprar cialis
2020-09-14, 17:29:58
anonymous from Germany  
rating
genaric cialis cheap red pill

[url= https://cialisverygo..alis[/url]
<a href=' https://cialisverygo..>cialis y tadalafi</a>

cialis daily 5 mg online
2020-09-14, 22:13:28
anonymous from Germany  
rating
cialis en ligne en australie

[url= https://cialisverygo..reiswerter tadalafil cialis[/url]
<a href=' https://cialisverygo..m/'>how does daily use cialis work</a>

cialis prices pharmacy
2020-09-15, 03:13:40
anonymous from Germany  
rating
buy cialis toronto

[url= https://cialisverygo..com/]india barata cialis genrica[/url]
<a href=' https://cialisverygo..m/'>buy cialis toronto</a>

recensioni cialis generico
2020-09-15, 03:23:17
anonymous from Germany  
rating
acquisto cialis in contrassegn

[url= https://cialisverygo..alis[/url]
<a href=' https://cialisverygo..gt;generic cialis online</a>

cialis et psa
2020-09-15, 05:24:33
anonymous from Germany  
rating
cialis et psa

[url= https://cialisverygo..escription cialis prices[/url]
<a href=' https://cialisverygo..'>cheap cialis</a>

how strong is cialis 20mg
2020-09-15, 07:08:16
anonymous from Germany  
rating
generic soft tab cialis

[url= https://cialisverygo..om/]online cialis[/url]
<a href=' https://cialisverygo..gt;generic cialis</a>

online cialis daily
You are on page 4 of 4, other pages: 1 2 3 [4]

 

 

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: