Link to home
Start Free TrialLog in
Avatar of liltyga
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-excel">
    <cfheader name="Content-Disposition" value="xyzReport_#dateFormat(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>
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

How many rows does the query output?
Avatar of liltyga
liltyga

ASKER

For these larger reports, sometimes over 3,000 rows.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of liltyga

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.
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_#dateFormat(now(),'mmddyyyy')#.xls>
OR....
 <cfheader name="Content-Disposition"
      value="inline; filename=xyzReport_#dateFormat(now(),'mmddyyyy')#.xls>
)
With the proper quotes of course ...;)
Avatar of liltyga

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 :)