SpreadsheetFormats无法按预期工作

时间:2019-07-02 15:56:17

标签: coldfusion cfml

我能够将查询中的数据填充到电子表格中。但是,我在获取“范围”格式以正常工作时遇到问题。特定列(日期)和行(标题)的格式工作正常。但是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>

这是结果 Green highlight is correct format, orange is incorrect.

对于所有三个“范围内”的格式化功能,我都得到相同的结果。格式在电子表格中停止。我希望整个数据集都能接受任何范围内的函数格式。

1 个答案:

答案 0 :(得分:1)

我用CF 2018,0,04,314546得到了相同的结果。可能只是XLS格式的限制。 切换到XLSX对我来说效果很好:

theSheet = SpreadsheetNew("Raw Data", true);

YMMV,但CF2018也可以使用SpreadsheetFormatColumns()代替SpreadsheetFormatCellRange()