perl mysql (2) perl CGI (1)
Exchange Links Links to us
|
General :: Programming :: perl :: perl CGI
CGI = Common Gateway Interface, a specification for transferring information between a web server and a CGI program. Here you find code snippets for CGIs written in perl.
Articles:
Featured Article
Perl script on web server sends Excel file to browserQuestion: 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
 | |  | | print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";
print "Content-type: application/octet-stream\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";
print '"1","Test, first one"' . "\n";
print '"2","Test, last one"' . "\n";
| |  | |  |
|
|
|