Export to Excel is generating a blank document
Hi,
We are using CF 2016. Whenever user tries to export data to excel (Sample code as below), document is appearing as blank. Blank meaning worksheets does not appear in the exported document. But if we try to save the file locally (Saved document is not loading as expected as well) and send the document over email, recipients are able to open the document with proper data. So issue is happening only when user tries to open / save the file locally.
I even tried to comment out cfcontent , cfheader and directly displayed WriteOutput(ResultTable.Trim() ). Data is appearing as expected. Problem with the exported document.
Can anyone please suggest the possible root cause for this issue?
Sample code for generating XLS:
<cfset Id = application.user.MVP.Id[session.Auth.GetUser_Record_ID()]>
<cfset Name = application.user.MVP.Name[session.Auth.GetUser_Record_ID()]>
<cfif isDefined("URL.format") and URL.format eq 'Excel'>
<cfscript>
URL.record_id = Id; // needed to submit everything as a single structure below
request = Application.MVP.data.getData(argumentCollection = URL);
TotalsByPeriod = 'Period,Record_ID,RunID,Fade,ExitStrategyID';
TotalsAcrossPeriods = 'Record_ID,RunID,Fade,ExitStrategyID, Investment Value,MI Proceeds';
AllDataByPeriod = 'Period,Record_ID,RunID,Fade,ExitStrategyID,LoanID,LoanNumber';
... Additional information
colList = request.ColumnList;
</cfscript>
<cfif ListFindNocase('TotalsByPeriod,AlDataByPeriod,OneDataByPeriod',Evaluate(URL.outputFormat))>
<cfset request.sort(request.findColumn("Period"),TRUE)>
</cfif>
<cfloop index="colIx" list="#Evaluate(URL.outputFormat)#">
<cfset colList = ListDeleteAt(colList,ListFindNoCase(colList,colIx))>
</cfloop>
<cfset colList = Evaluate(URL.outputFormat)&','&colList>
<cfsavecontent variable="ResultTable">
<table cellpadding="1" cellspacing="0" border="1" class="display" style="border-collapse:collapse;">
<thead>
<tr>
<cfloop index="colIx" list="#colList#">
<cfoutput><th nowrap="nowrap" style="padding-left:2px;padding-right:2px;">#Application.CL.Utilities.cleanColumn(colIx)#</th></cfoutput>
</cfloop>
</tr>
</thead>
<tbody>
<cfoutput query="request">
<tr>
<cfloop index="colIx" list="#colList#">
<cfif colIx eq 'Fade'>
<td style="padding-left:2px;padding-right:2px;">#LSNumberFormat(request[colIx][currentRow],'_.____')#</td>
<cfelseif ListFindNoCase(Evaluate(URL.outputFormat),colIx)>
<td style="padding-left:2px;padding-right:2px;">#request[colIx][currentRow]#</td>
<cfelse>
<td style="padding-left:2px;padding-right:2px;">#LSCurrencyFormat(request[colIx][currentRow],'local')#</td>
</cfif>
</cfloop>
</tr>
</cfoutput>
</tbody>
</table>
</cfsavecontent>
<!---Output excel --->
<cfheader name="Content-Disposition" value="attachment; filename=Data_#Id#_Run_#URL.runId#_Valuation_Report.xls"/>
<cfcontent type="application/msexcel" reset="true"/>
<cfset WriteOutput(ResultTable.Trim() )/>
<cfexit>
<cfelse>
<cfinclude template="./grids/dataGrid.cfm">
</cfif>
