Search code examples
excelcoldfusionformatcfspreadsheet

Can I add a spreadsheet row and then format it?


I'm using cfspreadsheet to generate an excel spreadsheet. I'm adding rows one by one. Immediately after I add the row, I want to format it. Something like this:

<cfset SpreadsheetAddRow(mySpreadsheet, "hi,this,is,a,test") />
<cfset SpreadsheetFormatRow(mySpreadsheet, 
   {
      fgcolor:red;
   }) />

However, for the formatrow function, you have to provide a row number. Is there any way to format the row I just added without keeping a running counter of what row I'm up to?


Solution

  • The spreadsheet object itself knows how many rows are in it, similar to a query object.

    <cfset CurrentRow = mySpreadsheet.RowCount />
    

    Updating your example so that it works in ACF9:

    <cfset SpreadsheetFormatRow(mySpreadsheet, 
       {
          fgcolor = 'red'
       }, mySpreadSheet.RowCount ) />