Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to return a excel file from

Status
Not open for further replies.

cjunkie

Programmer
Oct 29, 2003
9
US
I want to return a excel file from a cgi script. The cgi script generates some table data and can return it in HTML format. I also want the user to have the option to send it to excel. I have made this work by giving the cgi script a *.csv extension and setting the "Content-type:" to something other that "text/html" for example:

The CGI called data.csv outputs:

printf("Content-type: application/ms-excel\n\n");
followed by some data.

This is called by the following in an html page:

<p><a href=&quot;../cgi-bin/data.csv?param1=value1&quot;>Get the data from data.csv</a></p>

or

<form name=&quot;input&quot; action=&quot;../cgi-bin/data.csv&quot; method=&quot;Post&quot;>
<input type=&quot;submit&quot; name=&quot;test&quot; value=&quot;data.csv via form&quot;>
</form>

My problem(s):

1) It seems very crude to have to set the extension of the cgi script to .csv. I would like to know how to set the name and extension of the file from within the cgi (some more header info?).

2) IE 6 does not seem to be very interested in the Content-type I set in the respose header. If the cgi extension is *.csv, the IE asks if I want to save or open in Excel and it does not seem to matter what mime type I use. If the extension is *.cgi, then IE does not know what to do with the file regardless of the mime type I set. Shouldn't IE be using the mime type to decide what application to send the file to?

3) If I call my cgi data.csv, then IE offers to save the file as data.csv or open it in Excel. But, if I use a href to call the script and use a very long param=value list, then IE gives the file a random name with a .csv extension. What is going on here? Is the a restriction on the length of param=value list that I can use?

 
Hi mate,

I'm a little confused by your question, I don't see why you have to name the file CSV.

As for #3, the maximum URL length in IE (not sure about other browsers) is 2,048 characters.

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Wullie,

CSV is for Comma Separated Value, but in fact, the *.xls extension worked better. I’ve moved this issue to the “CGI” thread. Look there if you are interested in the resolution.

Thanks so much for your help. [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top