1

I am trying to create a spreadsheet (.XLS file) using Adobe ColdFusion - 8. The code that creates a spreadsheet is:

<cfsetting enablecfoutputonly="Yes">
<cfset date_from = "#URL.date_from#">
<cfset date_to = "#URL.date_to#">
<cfset query_id="#URL.queryID#">
<cfquery name="GetEmps" datasource="cfdocexamples">
 <!--- My SQL Queries Goes Here--->
</cfquery>

<cfcontent type="application/msexcel">
<cfheader name="Content-Disposition" value="filename=Employees.xls">
<cfoutput>
    <table cols="4">
        <cfloop query="getData">
            <tr>
                <td>#uid#</td>
                <td>#week#</td>
                <td>#book_count#</td>
            </tr>
        </cfloop>
    </table>
</cfoutput>

Whenever I run the page, an XLS sheet is created, but I cannot find any data. The size of the created XLS file is 0.

Please Note: The Query is correct(Since when I print the output as html, I can see the table without any error/warning).

** After reading comments: UPD**:

I had updated my code and only included important code snippet now.

UPD 2:

Whenever I commented the line <cfsetting enablecfoutputonly="Yes"> , xls file is created with expected data. However, when I opened the generated file, a dialogue appears: enter image description here

Please note the spreadsheet generated is perfect. Only thing that is bothering me is the above warning. Also Note: whenever I tried to open the spreadsheet in google-docs as a preview, it says, the file could not be opened due to corrupted format.

However, I am able to open it perfectly in an MS-Excel.

Even changing content type to : <cfcontent type="application/vnd.msexcel"> , I got the same warning.

Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71
  • I do not see where the query named 'getData' gets created. And what is ``? – Scott Stroz Jul 22 '13 at 15:26
  • this `` only needs to be `` Unless you're specifically outputting data `#` are rarely needed. – Matt Busche Jul 22 '13 at 17:20
  • 2
    @ritesh_NITW - That is because you are not really generating a *real* excel file (just html). The warning is caused by [Excel's Extension Hardening](http://stackoverflow.com/questions/940045/how-to-suppress-the-file-corrupt-warning-at-excel-download/940200#940200) security feature. It cannot be disabled on the server. The only way to avoid it is to ensure the content matches the extension. For example, you could use `cfspreadsheet` to generate a true excel file, or generate a CSV file instead, etc.. Just as long as the actual content matches the file extension in your `cfheader`. – Leigh Jul 22 '13 at 17:47

1 Answers1

2

While I cannot speak exactly how to implement this, I know the developers within my organization worked around it with the Apache POI. It seemed to do the trick for them. It does have to be completed with Java through Coldfusion. Here is an example of it.

Matt W
  • 131
  • 4