User Guide Cancel

SpreadsheetNew

 

Note:

You can find the CFFiddle demo of this function and other spreadsheet functions as part of a project that is shared with you.

Click the button below to launch CFFiddle.

To copy the project in your workspace in CFFiddle, follow the steps below:

  1. Log in with your Gmail or Facebook credentials.
  2. Navigate to the project in the left pane.
  3. Once you make some changes in any cfm in the project, a pop up displays asking you to save the project.
  4. Give the project a suitable name and click Save.

Description

Creates a new ColdFusion spreadsheet object that represents a single sheet of an Excel document.

Returns

ColdFusion Excel 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

Type Default

Description

sheetName

String None

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

xmlFormat

Boolean False

If true, the function creates a .xlsx file supported by Microsoft Office Excel 2007. If false, the function creates an .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>

Get help faster and easier

New user?