Skip to main content
Known Participant
October 14, 2018
Question

create .xlsx file using cfspreadsheet with more than 200K records in CF 10

  • October 14, 2018
  • 2 replies
  • 1520 views

Hello,

I am trying to create an excel sheet (xlsx) using cfspreadsheet which gets data through a query object (SQL Server) having more than 200K records. When attempting to do that the cfm page just runs for few minutes (have set timeout for the page as 3600s) and stop processing further without any error and at the same time the excel sheet does not get created.

The requirement is to let user download the excel sheet with very large number of records whenever they want, no fix schedule for it.

Note: For another instance, upon dumping the SQL query object alone on the page it displays the records (in this case approx. 80K) successfully in a minute (approx.) however, cfspreadsheet does not work for this even.

Any advise / thoughts would be greatly appreciated.

Thank you.

This topic has been closed for replies.

2 replies

EddieLotter
Inspiring
October 16, 2018

As a test, make the database query return only about ten records.

Does the ColdFusion script complete with such a small result set?

BhaveshKPAuthor
Known Participant
October 16, 2018

Thank you.

Actually, earlier it was already working for .xls file with maximum rows (65,536). Later the rows were increasing so the requirement was to generate .xlsx to accommodate very large set of rows.

I will try that to work with only few records.

BKBK
Community Expert
Community Expert
October 17, 2018

Use threads. Here is an example:

<cfscript>

thread action="run" name="createSheet" {

  filepath=expandpath(".") & "\" & "Orders.xlsx";

  // Get data from a query

  sql="SELECT orderid,customerfirstname,customerlastname,address,total,city FROM orders

  ORDER BY orderid";

  sqlParams={};

  artOrders=queryExecute(sql,sqlParams,{datasource="cfartgallery"});

  // Create a spreadsheet object with sheetname Art

  spreadsheetObj=spreadsheetNew("Art",true);

  // Add rows with data from query result. The data start from row 1, col 1.

  // The spreadsheet will have column names.

  spreadsheetAddrows(spreadsheetObj,ArtOrders,1,1,true,[""],true);

  dirName=GetDirectoryFromPath(GetCurrentTemplatePath());

  // Write spreadsheet to a file

  SpreadsheetWrite(spreadsheetObj,filepath,true);

}

thread action="run" name="downloadSheet" {

    filepath=expandpath(".") & "\" & "Orders.xlsx";

    cfheader(name="Content-Disposition", value="attachment; filename=Orders.xlsx");

    cfcontent(type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", file="#filepath#");

}

thread action="join" name="createSheet,downloadSheet";

</cfscript>

WolfShade
Legend
October 15, 2018

Hello, cfrbt,

Place the cfspreadsheet code within a CFTRY/CFCATCH and dump #cfcatch# in the catch portion to see what might be causing this to fail.  Also, check the logs in CFAdmin for any clues.

HTH,

^ _ ^

BhaveshKPAuthor
Known Participant
October 16, 2018

Thank you. I had done it already but with no success.