Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Coldfusion cfspreadsheet write error

New Here ,
May 15, 2018 May 15, 2018

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?

689
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 15, 2018 May 15, 2018

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

V/r,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 15, 2018 May 15, 2018

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

HTH,

^ _ ^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2019 Feb 25, 2019
LATEST

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">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources