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="../cgi-bin/data.csv?param1=value1">Get the data from data.csv</a></p>
or
<form name="input" action="../cgi-bin/data.csv" method="Post">
<input type="submit" name="test" value="data.csv via form">
</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?
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="../cgi-bin/data.csv?param1=value1">Get the data from data.csv</a></p>
or
<form name="input" action="../cgi-bin/data.csv" method="Post">
<input type="submit" name="test" value="data.csv via form">
</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?