我正在学习ColdFusion,我正在尝试使用spreadsheetFormatRows(spreadsheetObject,dataFormat,rangeOfRowsFormated)使用电子表格
如何将范围设置为包括除标题行(用于列名)之外的所有行?是否有一个函数可以返回 cfspreadsheet 对象上的行数,以便我可以将范围设置为"2 行计数"?
我尝试了spreadsheetFormatRows(theSheet, headerFormat, 2-50);
并且工作正常,并将第 2 行格式化为 50 行,但我不想进行硬编码。
提前谢谢你。
电子表格对象具有属性行计数。你可以做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>
在线试用
在填充行数时跟踪行数并将值保存到变量中。更简单的是,如果它们是查询结果,请使用 cfquery 中的 recordcount 变量。
请记住添加 1,以便设置最后一行的格式。