Coldfusion cfspreadsheet write error
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
I don't see where you are including the Spreadsheet object for the write.
V/r,
^ _ ^
Copy link to clipboard
Copied
You forgot to put hashtags around the variable name that is the Spreadsheet object "theSheet" should be "#theSheet#".
HTH,
^ _ ^
Copy link to clipboard
Copied
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">

