Skip to main content
Inspiring
November 3, 2008
Answered

Table structure to Excel

  • November 3, 2008
  • 5 replies
  • 1307 views
How can i send the below table and code to a Excel sheet?
Tried some things but isn't really working...

Thanks.

<h2>Polling statistics: #stprops_pollingdata.question#</h2>
<table border="1" cellpadding="1" cellspacing="2">
<tr>
<th>Date / Time created</th>
<th>Question</th>
<cfloop index="i" from="1" to="#application['wsoFarcryPolling' & pollingid]#">
<cfif stprops_pollingdata['answer' & i] GT 0>
<th>#stprops_pollingdata['answer' & i]#</th>
</cfif>
</cfloop>
<th>Total votes</th>
</tr>
<tr>
<td>#stprops_pollingdata.datetimecreated#</td>
<td>#stprops_pollingdata.question#</td>
<cfloop index="i" from="1" to="#application['wsoFarcryPolling' & pollingid]#">
<cfif stprops_pollingdata['answer' & i] GT 0>
<td>#sums .recordcount#</td>
</cfif>
</cfloop>
<td>#answers_sum#</td>
</tr>
</table>
    This topic has been closed for replies.
    Correct answer fober1
    hi,
    the example above works for probably most uses but be aware that this will not create correct number-format or date format cells in Excel.
    If you need to do further transactions of your data in Excel (as example: Pivot Tables, date sort, sums,...) then this will probably not work for you.

    In that case you should have a look at the Apache POI libraries.
    http://code.google.com/p/poi-for-coldfusion/

    This library allows you to create "real" excel files through a Java API. There are also some ColdFusion wrappers for that technology around.
    http://www.d-ross.org/index.cfm?objectid=9C65ED5A-508B-E116-6F4F7F38C6AE167C

    cheers,
    fober


    5 replies

    Inspiring
    November 5, 2008
    Interesting thanks for adding this info, although i stay with the poi functionality, with that you can make it as simple or as complicated you need. For future needs i just refer to the poi folder etc and done.

    Thanks
    November 5, 2008
    Using the poi resources are certainly more powerful, but for a simple, single-sheet excel document, don't forget that you can put "mso-number-format" in the cell style and save a bit of hassle. Some examples are here: http://www.netdominus.co.uk/knowledgebase/mod/resource/view.php?id=182
    Inspiring
    November 4, 2008
    Awesome, thanks all, i indeed found:

    http://www.bennadel.com/projects/poi-utility.htm
    fober1Correct answer
    Inspiring
    November 4, 2008
    hi,
    the example above works for probably most uses but be aware that this will not create correct number-format or date format cells in Excel.
    If you need to do further transactions of your data in Excel (as example: Pivot Tables, date sort, sums,...) then this will probably not work for you.

    In that case you should have a look at the Apache POI libraries.
    http://code.google.com/p/poi-for-coldfusion/

    This library allows you to create "real" excel files through a Java API. There are also some ColdFusion wrappers for that technology around.
    http://www.d-ross.org/index.cfm?objectid=9C65ED5A-508B-E116-6F4F7F38C6AE167C

    cheers,
    fober


    Inspiring
    November 3, 2008

    I would start with this..

    <!--- set content type to invoke Excel --->
    <cfcontent type="application/vnd.ms-excel">

    <!--- name for XLS file --->
    <!--- use "Content-Disposition" in cfheader for
    Internet Explorer --->
    <cfheader name="Content-Disposition" value="filename=labels.xls">
    <html>
    <head>
    .
    .

    Your code above
    .
    .
    </body>
    </html>

    See where that gets you :)

    IF you do search for formatting excel fields in coldfusion you should come up
    with the method you need to make sure your dates are formatted the way you want.

    I hope that helps some :)
    Chris
    Inspiring
    November 3, 2008
    Hi almost :) Now i use:

    <cfheader name="Content-Disposition" value="attachment;filename=pollingstats.xls">
    <cfcontent type="application/vnd.ms-excel">

    But when i trigger the code it seems i get a statement it's not in the correct .xls format......