Skip to main content
June 18, 2012
Question

query results to Excel problems

I'm trying to get results from a ColdFusion query called q to go into an Excel file.

There are 2 things going wrong.

1. An Excel message comes up that says "The file you are trying to open 'stc.xls', is in a different format than specified by the file extension..."

2. character values in col1 01,02,03,... are coming over to Excel as numbers 1,2,3,...

How do I fix those 2 things ?

This is the way I'm trying to do it.

<cfsetting enablecfoutputonly="yes">

<cfcontent type="application/msexcel">

<cfheader name="Content-Disposition" value="filename=test.xls">

<cfoutput>

   <table>

      <cfloop index="ii" from="1" to="#q.recordcount#">

         <tr>

            <td>

              #q.col1[ii]#

            </td>

            <td>

              #q.col2[ii]#

            </td>

         </tr>

      </cfloop>

   </table>

</cfoutput>

    This topic is closed to new replies. Start a new post to keep the conversation going.

    4 replies

    Inspiring
    June 18, 2012

    Using html table tags stopped working when MS introduced Office 2007.  Use cfspreadsheet instead.

    Translate
    June 18, 2012

    Thank you. That's just for version 9, right ?

    Translate
    Inspiring
    June 18, 2012

    cfspreadsheet was added for version 9.  If you are on an earlier version, check out this link.  http://www.bennadel.com/projects/poi-utility.htm

    Translate