views:

1413

answers:

2

I am using ColdFusion 8. Doing something like this:

<cfheader name="content-disposition" value="attachment; filename=abc.xlsx">
<cfcontent type="application/msexcel">
<html>

But I get a file like abc.xlsx.XLS.

The reason I'm trying to get an XLSX is because sometimes the XLS version is so large and Office 2007 gets stuck opening it or takes way to long.

Only workaround right now is to wait, open the XLS in Office 2007, save as .XLSX and then open it faster.

Any help is appreciated!

+3  A: 

I believe that the MIME type for Excel 2007 .xlsx files is "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". I found an article on the Office Resource Kit Blog that calls this out after googling around a little.

D.Shawley
Thank you for your prompt response!I tried it and these are the results:<cfheader name="content-disposition" value="attachment; filename=MyPriceList"><cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"> This opens the file, but slowly, I have to do a 'save as' as it doesnt have an extension.Once I do a save as xlsx, and open the saved file, it opens really fast. (so same issue as downloading a .xls file)
<cfheader name="content-disposition" value="attachment; filename=MyPriceList.xlsx"><cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"> "Excel cannot open the file 'abc.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file". Even if instead of opening attachment I save it, I cannot open it (same message)
I was just using abc as an alias for MyPriceList, please ignore the discrepancy
I also notice first attempt (below) it opens it as a XSLX, rather than XLSX.<cfheader name="content-disposition" value="attachment; filename=MyPriceList"> <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
+3  A: 

I would suggest that the slow opening is because you are providing the data in an HTML format, not because of the extension. You could test this by saving the file directly from the browser, renaming it with the xlsx file extension, and opening it.

If you want to save data in an Excel format directly, I would check out Ben Nadel's POI CFC project.

Ben Doom
Thanks to all. Also found some resources on using XML to load excel file directly.
https://blogs.wharton.upenn.edu/brainstorm/2008/01/reading-and-writing-excel-file.htmland http://www.bennadel.com/blog/461-Creating-Microsoft-Excel-Documents-With-ColdFusion-And-XML.htm