ColdFusion 9.0 Resources |
SpreadsheetAddColumnSee alsoSpreadsheetAddImage, SpreadsheetAddRow, SpreadsheetAddRows, SpreadsheetDeleteColumn, SpreadsheetDeleteColumns, SpreadsheetFormatColumn, SpreadsheetFormatColumns, SpreadsheetShiftColumns Parameters
UsageThe spreadsheetaddcolumn function can accept either two or five arguments. You can specify the spreadsheetaddcolumn function using two parameters as follows: <cfset spreadsheetAddColumn(SpreadsheetObj,"newcol1,newcol2,newcol3")> You can specify the spreadsheetaddcolumn function using five parameters as follows: <cfset spreadsheetAddColumn(SpreadsheetObj,"newcol1,newcol2,newcol3",2,3,false)> ExampleThe following example creates an Excel spreadsheet object from a query and inserts a new column 2, with data starting at row 3. The existing columns 2 and greater increment by one. <!--- Get the spreadsheet data as a query. ---> <cfquery name="courses" datasource="cfdocexamples" cachedwithin="#CreateTimeSpan(0, 6, 0, 0)#"> SELECT CORNUMBER,DEPT_ID,COURSE_ID,CORNAME FROM COURSELIST </cfquery> <cfscript> ///We need an absolute path, so get the current directory path. theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & courses.xls"; //Create a new Spreadsheet object and add the query data. theSheet = SpreadsheetNew("CourseData"); SpreadsheetAddRows(theSheet,courses); //Insert a new second column to the sheet, with data starting in row 3. SpreadsheetAddColumn(theSheet, "Basic,Intermediate,Advanced,Basic,Intermediate,Advanced,Basic,Intermediate,Advanced" ,3,2,true); </cfscript> <!--- Write the spreadsheet to a file, replacing any existing file. ---> <cfspreadsheet action="write" filename="#theFile#" name="theSheet" sheet=1 sheetname="courses" overwrite=true> |