Skip to main content
WolfShade
Legend
September 18, 2012
Answered

CFQuery -> Excel file

  • September 18, 2012
  • 1 reply
  • 5119 views

Hello, everyone.

I'm trying to take a query object and insert the data into an Excel file.  I've tried the CFCONTENT/CFHEADER route, and I get the error message about the file not being the same type as the extension.

Is there a better way to get data into an Excel file?

Thank you,

^_^

This topic has been closed for replies.
Correct answer WolfShade

With regards to, "<cfcontent file="filename" type="application/msexcel"> (as opposed to "application/vnd.ms-excel").", when I changed my type I match yours, there was no change in behaviour.

Regarding, "

Before changing the type of the cfcontent, it would say "The file you are opening 'filename.xls' is not the same type as the file extension."

After changing the type of the cfcontent, it now says "The file you are opening 'export.cfm' is not the same type as the file extension."",

That sounds like what we were seeing when we were using html table tags to generate our content.  Things worked well until Office 2007 came out and then it got ugly.  I suspect that when you say that your code is almost exactly the same as mine, you have a different definition of "almost" than do I.


I found the solution here.  I don't know why it works, but it does.

I've tried it with the Excel, it works flawlessly; I'm about to apply it to the CSV in a moment. 

^_^

1 reply

Inspiring
September 18, 2012

start with cfspreadsheet.

WolfShade
WolfShadeAuthor
Legend
September 18, 2012

Trying your suggestion, I'm using CFSPREADSHEET to create the file directly from the query, but the file is blank even when the query has 886 records in it.

Also, how do I tell the browser to offer the file for download, once it's made, without using CFCONTENT and CFHEADER?

Thank you,

^_^

Inspiring
September 18, 2012

One step at a time, starting with why cfspreadsheet is producing a blank file.  Please post the code you are using to create this file.  Just the code that creates the file, no queries, formatting stuff or anything else.