温馨提示:本文翻译自stackoverflow.com,查看原文请点击:coldfusion - SpreadsheetFormats not working as expected
coldfusion cfml

coldfusion - SpreadsheetFormats无法按预期工作

发布于 2020-03-27 11:52:45

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

这是结果 绿色突出显示格式正确,橙色不正确。

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

查看更多

查看更多

提问者
Mike
被浏览
91
Ageax 2019-07-03 23:20

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

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

YMMV,但也可用于SpreadsheetFormatColumns()代替CF1的CF2018 SpreadsheetFormatCellRange()