liltyga
asked on
Generating Excel Files With ColdFusion
Hi, I am generating Excel files from ColdFusion, and most of the time the Excel generation is working, but in some instances (from what I can tell, when the query is very large), instead of outputting the formatted HTML within Excel, the actual HTML code displays within Excel. Does anyone have any ideas as to why this may be happening?
Here is what the code basically looks like:
<cfif isDefined ('url.excel') and url.excel eq 1>
<cfcontent type="application/vnd.ms-e xcel">
<cfheader name="Content-Disposition" value="xyzReport_#dateForm at(now(),' mmddyyyy') #.xls>
</cfif>
<cfquery name="queryName" datasource="#dsn#">
SQL Code
</cfquery>
<cfoutput>
<h1>Report Name</h1>
<cfloop query="queryName">
<table>
<tr>
<td>Data output goes in this table</td>
</tr>
</table>
</cfloop>
</cfoutput>
Here is what the code basically looks like:
<cfif isDefined ('url.excel') and url.excel eq 1>
<cfcontent type="application/vnd.ms-e
<cfheader name="Content-Disposition"
</cfif>
<cfquery name="queryName" datasource="#dsn#">
SQL Code
</cfquery>
<cfoutput>
<h1>Report Name</h1>
<cfloop query="queryName">
<table>
<tr>
<td>Data output goes in this table</td>
</tr>
</table>
</cfloop>
</cfoutput>
How many rows does the query output?
ASKER
For these larger reports, sometimes over 3,000 rows.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi aqx:
Thanks for the feedback! Sorry, no, I'm looping the <tr>s, not the tables; just quickly trying to recap what was going on. I'll give your ideas a try in the morning and let you know how they work out.
Thanks for the feedback! Sorry, no, I'm looping the <tr>s, not the tables; just quickly trying to recap what was going on. I'll give your ideas a try in the morning and let you know how they work out.
Sounds good.
(BTW: For tomorrow ...
If that's the real cfheader, it's missing a few attributes. It should be more like
<cfheader name="Content-Disposition"
value="attachment; filename=xyzReport_#dateFo rmat(now() ,'mmddyyyy ')#.xls>
OR....
<cfheader name="Content-Disposition"
value="inline; filename=xyzReport_#dateFo rmat(now() ,'mmddyyyy ')#.xls>
)
(BTW: For tomorrow ...
If that's the real cfheader, it's missing a few attributes. It should be more like
<cfheader name="Content-Disposition"
value="attachment; filename=xyzReport_#dateFo
OR....
<cfheader name="Content-Disposition"
value="inline; filename=xyzReport_#dateFo
)
With the proper quotes of course ...;)
ASKER
Thanks again! I think I'm on to something; even after reducing the query to output 15 rows max, use the cfsetting enableCFOutputOnly = true, and switched the the order of cfheader and cfoutput, I get the finicky HTML output. (There are several other reports that are working just fine, so I am stepping through the code; when I remove the last half of the report, it generates just fine, so it seems to be a matter of figuring out what the offending code is. I may not have gotten to this point as quickly though, without your help!
Glad I could help :)