Ritesh Kumar Gupta
Ritesh Kumar Gupta

Reputation: 5191

Creating XLS file Using ColdFusion

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.

Upvotes: 1

Views: 1497

Answers (1)

Matt W
Matt W

Reputation: 130

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.

Upvotes: 2

Related Questions