SpreadsheetFormats 未按预期工作
SpreadsheetFormats not working as expected
我能够将查询中的数据填充到电子表格中。但是,我在使 "ranged" 格式正常工作时遇到问题。特定列(日期)和行(header)的格式工作正常。但是 SpreadsheetFormatColumns, ...Rows, ...CellRange 不是。我需要为整个数据集设置字体和字体大小。
这是我试过的。
<cfscript>
//Current directory path.
theFile = GetDirectoryFromPath(GetCurrentTemplatePath()) & "GridDump.xls";
//Create a new Excel spreadsheet object and add the query data.
theSheet = SpreadsheetNew("Raw Data");
FormatDate.dataformat = "dd-mmm-yy";
//Get Row Count and Row Range
RC = toString(result.recordcount+1);
RR = "1-" & RC;
//Get Column Count
CC = toString(ListLen(GridFieldNames));
//Get Column Letter
CL = chr(CC + 64);
//Get Column Range (Nummerical)
CRN = "1-" & CC;
//Get Column Range (Alphabetical)
CRA = "A-" & CL;
//Set Sheet Format
WholeSheet = StructNew();
WholeSheet.font="Consolas";
WholeSheet.fontsize=12;
//Set header Row Format
HeadRow = StructNew();
HeadRow.bold="true";
//Insert the Header Row
SpreadsheetAddRow(theSheet,GridFieldNames);
//Insert the Data
SpreadsheetAddRows(theSheet,result);
//Format the Data
SpreadsheetFormatCellRange(theSheet,WholeSheet,1,1,RC,CC);
//SpreadsheetFormatRows(theSheet,WholeSheet,RR);
//SpreadsheetFormatColumns(theSheet,WholeSheet,CRN);
SpreadsheetFormatRow(theSheet,HeadRow,1);
//Header Row
SpreadsheetFormatColumn(theSheet,FormatDate,1);//Date Column
SpreadsheetAddFreezePane(theSheet,0,1);//Top Row Only
//SpreadSheetAddAutofilter(theSheet,"A1:J1");
</cfscript>
这是结果
我对所有三个 "ranged" 格式化函数得到相同的结果。该格式在电子表格中途停止。我希望整个数据集接受任何范围函数格式。
我用CF 2018,0,04,314546得到了相同的结果。可能只是 XLS 格式的限制。
切换到 XLSX 对我来说效果很好:
theSheet = SpreadsheetNew("Raw Data", true);
YMMV,但也适用于 CF2018 的是使用 SpreadsheetFormatColumns()
而不是 SpreadsheetFormatCellRange()
。
我能够将查询中的数据填充到电子表格中。但是,我在使 "ranged" 格式正常工作时遇到问题。特定列(日期)和行(header)的格式工作正常。但是 SpreadsheetFormatColumns, ...Rows, ...CellRange 不是。我需要为整个数据集设置字体和字体大小。
这是我试过的。
<cfscript>
//Current directory path.
theFile = GetDirectoryFromPath(GetCurrentTemplatePath()) & "GridDump.xls";
//Create a new Excel spreadsheet object and add the query data.
theSheet = SpreadsheetNew("Raw Data");
FormatDate.dataformat = "dd-mmm-yy";
//Get Row Count and Row Range
RC = toString(result.recordcount+1);
RR = "1-" & RC;
//Get Column Count
CC = toString(ListLen(GridFieldNames));
//Get Column Letter
CL = chr(CC + 64);
//Get Column Range (Nummerical)
CRN = "1-" & CC;
//Get Column Range (Alphabetical)
CRA = "A-" & CL;
//Set Sheet Format
WholeSheet = StructNew();
WholeSheet.font="Consolas";
WholeSheet.fontsize=12;
//Set header Row Format
HeadRow = StructNew();
HeadRow.bold="true";
//Insert the Header Row
SpreadsheetAddRow(theSheet,GridFieldNames);
//Insert the Data
SpreadsheetAddRows(theSheet,result);
//Format the Data
SpreadsheetFormatCellRange(theSheet,WholeSheet,1,1,RC,CC);
//SpreadsheetFormatRows(theSheet,WholeSheet,RR);
//SpreadsheetFormatColumns(theSheet,WholeSheet,CRN);
SpreadsheetFormatRow(theSheet,HeadRow,1);
//Header Row
SpreadsheetFormatColumn(theSheet,FormatDate,1);//Date Column
SpreadsheetAddFreezePane(theSheet,0,1);//Top Row Only
//SpreadSheetAddAutofilter(theSheet,"A1:J1");
</cfscript>
这是结果
我对所有三个 "ranged" 格式化函数得到相同的结果。该格式在电子表格中途停止。我希望整个数据集接受任何范围函数格式。
我用CF 2018,0,04,314546得到了相同的结果。可能只是 XLS 格式的限制。 切换到 XLSX 对我来说效果很好:
theSheet = SpreadsheetNew("Raw Data", true);
YMMV,但也适用于 CF2018 的是使用 SpreadsheetFormatColumns()
而不是 SpreadsheetFormatCellRange()
。