How to determine the number of lines in a cfspreadsheet object?

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

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

I tried spreadsheetFormatRows(theSheet, headerFormat, 2-50);

and worked fine and formats lines 2 through 50, but I don't want to have it hardcoded.

Thanks in advance.

+3


source to share


2 answers


Keep track of the number of lines as they fill and store the value of the variable. However, if they are query results, use the recordcount variable from cfquery.



Remember to add 1 so that you format the last line.

+1


source


The spreadsheet object has a rowcount attribute. You can dospreadsheetFormatRows(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

+3


source







All Articles