SpreadsheetNew

Description

Creates a ColdFusionExcel spreadsheet object, which represents a single sheet of an Excel document.

Returns

ColdFusionExcel spreadsheet object.

Category

Microsoft Office Integration

Function syntax

SpreadsheetNew([sheetName, xmlformat])

See also

All Other Spreadsheet* functions; see Microsoft Office Integration list.

History

ColdFusion 9: Added the function.

Parameters

Parameter

Description

sheetName

A string containing the sheet name to assign to the Excel spreadsheet object.

xmlformat

A Boolean value.

True or Yes: Creates a .xlsx file that is supported by Microsoft Office Excel 2007.

False or No: Creates a .xls file.

Usage

This function supports Microsoft Office Excel 2007.

To create a simple .xls spreadsheet object with a default worksheet name, your code can be as follows:

<cfset SpreadsheetObj = spreadsheetNew()>

To create a simple .xls spreadsheet object by specifying the worksheet name as "mySheet", your code can be as follows:

<cfset SpreadsheetObj = spreadsheetNew("mySheet")>

To create spreadsheet objects that are supported by Microsoft Office Excel 2007 (.xlsx), your code can be as follows:

<cfset SpreadsheetObj = spreadsheetNew("true")>
<cfset SpreadsheetObj = spreadsheetNew("mysheet","yes")>
Note: You can specify either “true" or "yes" to create a .xlsx file.

Example

The following example creates an Excel spreadsheet object with the sheet name Expenses, sets a cell value, and saves the result to a 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"); 
    //Set the value a cell. 
    SpreadsheetSetCellValue(theSheet,"365",1,4); 
</cfscript> 
 
<!--- Write the spreadsheet to a file, replacing any existing file. ---> 
<cfspreadsheet action="write" filename="#theFile#" name="theSheet" overwrite=true>