Skip to main content
Participant
May 15, 2018
Question

Coldfusion cfspreadsheet write error

  • May 15, 2018
  • 3 replies
  • 707 views

I am using Coldfusion 2016 on rhl7 and cant write a spreadsheet file.

<cfscript>

///We need an absolute path, so get the current directory path.

theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "newSpreadsheet.xls";

//Create a new Excel spreadsheet object.

theSheet = SpreadsheetNew("Expenses");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

</cfscript>

<!--- Write the spreadsheet to a file, replacing any existing file. --->

<cfspreadsheet action="write" filename="#theFile#" name="theSheet" overwrite=true sheetname = "Expenses">

Returns the following error:

An exception occurred while using action=write.

java.lang.ArrayIndexOutOfBoundsException: 0

Can anyone help?

This topic has been closed for replies.

3 replies

Participant
February 25, 2019

dont need to put # on the name, more likely it will cause an error, what I think might be your issue is you havent set the sheet as active before trying to put any information on it, try like this...

<cfscript>

///We need an absolute path, so get the current directory path.

theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "newSpreadsheet.xls";

//Create a new Excel spreadsheet object.

theSheet = SpreadsheetNew("Expenses");

SpreadSheetSetActiveSheet(theSheet, "Expenses");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

SpreadSheetAddRow(theSheet,"Order,First Name,Last Name,Address,Amount,City");

</cfscript>

<!--- Write the spreadsheet to a file, replacing any existing file. --->

<cfspreadsheet action="write" filename="#theFile#" name="theSheet" overwrite=true sheetname = "Expenses">

WolfShade
Legend
May 15, 2018

You forgot to put hashtags around the variable name that is the Spreadsheet object "theSheet" should be "#theSheet#".

HTH,

^ _ ^

WolfShade
Legend
May 15, 2018

I don't see where you are including the Spreadsheet object for the write.

V/r,

^ _ ^