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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

presenting a csv file

Status
Not open for further replies.

andy61

Technical User
Apr 19, 2006
59
GB
I am writing an intranet cgi script in ksh to accept certain params from a form and present back to the browser a spreadsheet (csv). I can create the csv easily enough, but I'd like the spreadhsheet to be immediately presented. Although I've limited experience of cgi, it seems to me that I have to present the user with a page generated by the script that contains a link to the csv rather than just returning the spreadsheet.
Sorry if this seems a daft question !
 
Hi

andy61 said:
I can create the csv easily enough, but I'd like the spreadhsheet to be immediately presented.
What do you mean "immediately" ? Or what would be "non-immediately" ?
Code:
[highlight #eee]#!/bin/ksh[/highlight]
[b]echo[/b] -e [i]"Content-type: text/csv\r"[/i]
[b]echo[/b] -e [i]"\r"[/i]

cat filename.csv
or
Code:
[highlight #eee]#!/bin/ksh[/highlight]
[b]echo[/b] -e [i]"Content-type: text/csv\r"[/i]
[b]echo[/b] -e [i]"\r"[/i]

cat <<EOT
col1,col2,"col nr 3"
1,2,3.14
EOT
Tested with (pd)[tt]ksh[/tt].

Feherke.
 
Thanks for this. I thought I'd not made it very clear. I wanted the spreadsheet to be returned from the form rather than having to return a link to it. The text/csv content type returned a spreadsheet, but didn't put comma separated text in different columns (poss character set ?). However your response did point me in the direction of using content-type and I've found using
echo "Content-type: application/vnd.ms-excel" works. The only problemette is that the worksheet name is taken from the script name, but unless anyone knows a quick and easy solution I can live with that. Thanks for the steer

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top