coldfusionrowcountcfspreadsheet

How can I define the number of rows on cfspreadsheet object?


I am in the process of learning ColdFusion and I am trying to work with spreadsheets using spreadsheetFormatRows(spreadsheetObject, dataFormat, rangeOfRowsFormated)

How can I set the range to include all of the rows, except the header row, which is for column name? Is there a function that returns the number of the rows on cfspreadsheet object, so I can set the range to '2-rowCount'?

I tried spreadsheetFormatRows(theSheet, headerFormat, 2-50); and works fine and formats rows 2 to 50, but I don't want to have that hard-coded.

Thank you in advance.


Solution

  • The spreadsheet object has an attribute rowcount. You can do spreadsheetFormatRows(theSheet, format, "2-#theSheet.rowCount#");

    <cfscript>
        mySheet = spreadSheetNew("My Sheet");
        spreadSheetAddRow(mySheet, "'Col. A','Col. B','Col. C'");
        for(i=1; i <= RandRange(1, 100); i++){
            spreadSheetAddRow(mySheet, "'Row A#i#','Row B#i#','Row C#i#'");
        }
        spreadSheetFormatRow(mySheet, {bold = true, fontsize = 24}, 1);
        spreadSheetFormatRows(mySheet, {fontsize = 16}, "2-#mySheet.rowcount#");
        cfheader(name = "Content-Disposition", value = 'inline; fileName="test.xls"');
        cfcontent(type="application/vnd.ms-excel", variable="#spreadSheetReadBinary(mySheet)#");
    </cfscript>
    

    Try Online