I’m using the code below to export data from a database to an Excel sheet. What I want to do is have a certain set of fields be exported to a different sheet in the same workbook. The end result being that each person’s data is on a separate sheet rather than all combined on the same sheet like this code is doing. Any thoughts as to how I can write a formula or a piece of ColdFusion than will let me do this?
Also I’m using ColdFusion 8 so I can’t use the cfspreadsheet function.
<!--- use cfsetting to block output of HTML
outside of cfoutput tags --->
<cfsetting enablecfoutputonly="Yes">
<!--- set content type to invoke Excel --->
<cfcontent type="application/msexcel">
<!--- suggest default name for XLS file --->
<!--- use "Content-Disposition" in cfheader for
Internet Explorer --->
<cfheader name="Content-Disposition" value="filename=export.xls">
<!--- output data using cfloop & cfoutput --->
<cfquery name="qquestionnaire_export" datasource="mydatabase">
Select * from registration
</cfquery>
<cfoutput>
<table>
<tr><td align="center">Transfer Registration Questionnaire</td>
<td></td>
</tr>
<th>Credit Category</th>
<th>Completed Degree</th>
<th>Highest Degree</th>
</cfoutput>
<cfloop query="qquestionnaire_export">
<cfoutput>
<tr>
<td align="center">#credit_category#</td>
<td align="center">#completed_degree#</td>
<td align="center">#highest_degree#</td>
</tr>
</cfoutput>
</cfloop>
<cfoutput><tr><td height="10"></td></tr></cfoutput>
<cfoutput></table></cfoutput>
If you can’t use
<cfspreadsheet>, then I suggest using the Apache POI project instead of the simple “HTML as Excel via CFCONTENT” approach. POI enables you to create actual Excel spreadsheets with all of the fun that’s associated with them.Ben Nadel has a CFC wrapper that exposes the multi-sheet parts of the API.
http://www.bennadel.com/projects/poi-utility.htm