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

problem returning CSV/Excel file

Status
Not open for further replies.

krisplus5

Programmer
Oct 4, 2001
44
US
I've got a ColdFusion application where I generate a comma-separated-values (CSV) file from code, and return it to the client via a link. Generally this opens as an excel document for the client. It's pretty simple, just 2 columns, and it's been working fine for years.

Now I need to return the file to the client without the intermediary link. I just can't seem to get it to work. I've tried CFLOCATION to the file, and CFCONTENT to return the file. Both of these methods return the file, launching excel, but all the content ends up in the first column in the spreadsheet instead of in 2 columns as expected. This behavior also strips the quotes off of the first column data for every record, so that the data in the first column of the excel spreadsheet looks something like this:

ID,"Title"
ABC,"Title for record ABC"
DEF,"Exciting Title Here"

If I call the file from the address line it works fine, parsing the CSV file into the 2 columns in excel. I suspect that this is some kind of buffer issue, but don't know how to handle it. And, strangely, calling an RTF file without the intermediary link works just fine (popping Word in the browser).

Any and all suggestions are greatly appreciated.

Cheers,
Kris
 
When you're using CFCONTENT, what MIME type are you specifying?

Try
Code:
<CFCONTENT type=&quot;application/vnd.ms-excel&quot;>
rather than simply
Code:
<CFCONTENT type=&quot;application/msexcel&quot;>

you might also try
Code:
<CFCONTENT type=&quot;text/csv&quot;>


-Carl
 
Hi Carl,

Thanks for the suggestions. I had tried both type=&quot;application/vnd.ms-excel&quot; and type=&quot;text/csv&quot;

Both resulted the same. The strange thing here is that if I return a clickable link to the file it works fine. Only when I redirect using CFLOCATION or CFCONTENT does the problem appear.

Kris
 
Did you try using CFHEADER with CFCONTENT?
Code:
<CFHEADER NAME=&quot;Content-Disposition&quot; VALUE=&quot;inline; filename=myfile.xls&quot;>
<CFCONTENT TYPE=&quot;application/unknown&quot; file = &quot;c:\files\myfile.xls&quot;>
Fig Leaf Software has a good demonstration page here:


-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top