Description
Merges a rectangular block of two or more Excel spreadsheet object cells.
Returns
Does not return a value.
Category
Microsoft Office Integration
Function syntax
SpreadsheetMergeCells(spreadsheetObj, startRow, endRow, startColumn, endColumn) |
See also
SpreadsheetGetCellComment, SpreadsheetFormatCell, SpreadsheetGetCellFormula, SpreadsheetGetCellValue,
SpreadsheetSetCellComment, SpreadsheetSetCellFormula, SpreadsheetSetCellValue
History
ColdFusion 9: Added the function.
Parameters
Parameter |
Description |
---|---|
spreadsheetObj |
The Excel spreadsheet object containing the cells to merge. |
startRow |
The number of the first row to merge. |
endRow |
The row number of the last row to merge. |
startColumn |
The column number of the first cell to merge. |
endColumn |
The column number of the last cell to merge. |
Usage
If you merge two cells using this function, the merged cell by default displays the value in the cell that is on the left-hand side of the spreadsheet. For example, if you merge the cell (20,3) and cell (20,4), then the value in the cell (20, 3) is displayed. If the cell (20, 3) is blank, then after merging, the cell displays blank.
Example
The following example merges cells 4-6 in rows 1-3 of an Excel spreadsheet object. It puts text in the merged cells and saves the sheet to a file so you can see the result.
<cfscript> ///We need an absolute path, so get the current directory path. theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "mergecells.xls"; //Create a new Excel spreadsheet object and add the query data. theSheet = SpreadsheetNew("CourseData"); //Merges cells 4-6 in the first three rows of the Excel spreadsheet object. SpreadsheetMergeCells(theSheet,1,3,4,6); //Set the value of the merged cell. SpreadsheetSetCellValue(theSheet,"Columns 4-6 of rows 1-3 are merged",1,4); </cfscript> <!--- Write the spreadsheet to a file, replacing any existing file. ---> <cfspreadsheet action="write" filename="#theFile#" name="theSheet" overwrite=true> |