Link to home
Start Free TrialLog in
Avatar of tribalboy3000
tribalboy3000

asked on

Need help exporting Coldfusion to Excel?

I've been going thru the EE solutions on how to export my Coldfusion table(query output) to MS Excel 2007. I have most of it working but need some help to finish.

 What Im trying to do is add a download button to my page so when it is clicked the info on that page is downloaded as an Excel document.

When I click the download button it prompts to save or open the document "myfile.xls". When I open the file I get the following:

1. I get a message that myfile.xls, is a different format than specified file extension. Would you like to open anyway.

2. I get another message after I click ok, that  its missing  default.css file. But the colors and formatting is exactly as on the webpage.

3. Most important feature thats missing is the data...The headings are in the Excel Doc, but the cells where there is suppose to be data are empty.

Thanks
<!--- My Queries are above here which ain't the problem--->
 
<!--- set vars for special chars --->
<cfset TabChar = Chr(9)>
<cfset NewLine = Chr(13) & Chr(10)>
<!---  IF Button Clicked download EXCEL --->
<CFPARAM NAME="form.ExportExcel" TYPE="any" DEFAULT="0">
<cfif #form.ExportExcel# EQ "Download-Excel">
<!--- use "Content-Disposition" in cfheader for Internet Explorer  --->
<cfheader name="Content-Disposition" value="attachment; filename=FTE_REPORT_#dateformat(Now(),"mm-dd-yyyy")#.xls">
<!--- set content type to invoke Excel --->
<cfcontent type="application/msexcel">
 
</cfif>
 
 
</head>
 
<body>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFCC00"><h1> &nbsp;FTE by Course</h1></td>
</tr>
</table><p>
<!--- Drop Menu --->
<cfinclude template="inc_selector_2.cfm"><br />
<br />
<!--- Export Button --->
<form id="Export2" name="Export2" method="post" ">
  <label>
    <input type="submit" name="ExportExcel" id="ExportExcel" value="Download-Excel" /> </label>
  <br />
</form>
 
 
 
 
<table width="100%" border="1" cellspacing="3" cellpadding="3">
  <tr>
    <td width="52%"> </td>
    <td width="16%" bgcolor="#FFCC00"><h2>2007-08</h2></td>
    <td width="16%" bgcolor="#FFCC00"><h2>2008-09</h2></td>
    <td width="16%"> </td>
  </tr>
  <tr>
    <td><h2>Courses</h2></td>
    <td><h2>FTE</h2></td>
    <td><h2>FTE</h2></td>
    <td><h2>1-Yr Change (#)</h2></td>
  </tr>
  <!--- formatting for decimals #LSNUMBERFORMAT(FTE_89, 0.0000)#--->
  <cfset yr_change = 0>
 
<cfoutput query="get_results78" group="Number">
 
<cfset yr_change = get_results78.FTE_89 - get_results78.FTE_78>
 
  <tr>
    <td class="body">#get_results78.Number# #get_results78.Name#</td>
 
  
    <td class="body">#LSNUMBERFORMAT(get_results78.FTE_78, 0.00)#</td>
    <td class="body">#LSNUMBERFORMAT(get_results78.FTE_89, 0.00)#</td>
    <td><span class="<cfif yr_change LT 0>minus<cfelse>body</cfif>">#LSNUMBERFORMAT(yr_change, 0.00)#</span></td>
  </tr>
 
 </cfoutput>
   <cfset yr_change2 = 0>
 <cfoutput query="get_results89" group="Number">
 <cfset yr_change2 = get_results89.FTE_89 - get_results89.FTE_78>
 <cfif Yr_78 EQ 0>
  <tr>
    <td class="body">
    #get_results89.Number# #get_results89.Name#</td>
    <td class="body">#LSNUMBERFORMAT(get_results89.FTE_78, 0.00)#</td>
    <td class="body">#LSNUMBERFORMAT(get_results89.FTE_89, 0.00)#</td>
    <td> <span class="<cfif yr_change2 LT 0>minus<cfelse>body</cfif>">#LSNUMBERFORMAT(yr_change2, 0.00)#</span>
    </td>
  </tr>
    </cfif>
</cfoutput>
 
  <tr>
    <td class="body"><h2>Totals</h2></td>
    <td class="body">
   
	<!--- Sum for 2007-8 --->
   
	<cfoutput >
    <!---#GrandTotal78#--->
    #LSNUMBERFORMAT(theTotals78, 0.00)#
	</cfoutput>
   
    </td>
    <!--- Sum for 2007-8 --->
    <td class="body">
	<cfoutput  >
    <!---#GrandTotal89#---> 
    #LSNUMBERFORMAT(theTotals89, 0.00)#
	</cfoutput></td>
    <cfset YrTotals = 0>
    <cfset YrTotals = theTotals89 - theTotals78  >
    <td class="body"><cfoutput><span class="<cfif YrTotals LT 0>minus<cfelse>body</cfif>">#LSNUMBERFORMAT(YrTotals, 0.00)#</span></cfoutput></td>
  </tr>
 
</table>
 
       
 
</body>
</html>

Open in new window

Avatar of duncancumming
duncancumming
Flag of United Kingdom of Great Britain and Northern Ireland image

If you're exporting to excel, things like this are superfluous and might be causing the problem:
</head>
 
<body>


<!--- Drop Menu --->
<cfinclude template="inc_selector_2.cfm"><br />
<br />


<!--- Export Button --->
<form id="Export2" name="Export2" method="post" ">
  <label>
    <input type="submit" name="ExportExcel" id="ExportExcel" value="Download-Excel" /> </label>
  <br />
</form>

The only thing you should have, for the Excel version, is that table and all its contents.

ASKER CERTIFIED SOLUTION
Avatar of erikTsomik
erikTsomik
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 tribalboy3000
tribalboy3000

ASKER

That worked! Thank you!