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

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy