excel - 电子表格函数将日期转换为文本

标签 excel coldfusion spreadsheet coldfusion-11

我在 Excel 报告中使用电子表格函数,但在导出到 Excel 时它会将日期转换为文本。因此,我在 SpreadSheetSetCellValue 中使用了数据类型“日期” ,因此第一列中的值可以转换为客户想要的任何日期格式。这是代码:

 <cfset SpreadsheetSetCellValue(objSheet, '#RecordDate#', iRow, 1, 'Date')>

这工作正常,但是当我稍后将背景颜色应用于交替行时:

<cfset stFormat.AlternateRow = StructNew()>
<cfset stFormat.AlternateRow.fgcolor = 'yellow'>

<cfif (iRow mod 2) IS 0>
    <cfset SpreadsheetFormatRow(objSheet, stFormat.AlternateRow, iRow)>
</cfif>

它将该行中的所有列转换为“日期”格式。而我只希望每行中的第一列是“日期”日期类型。

最佳答案

对我来说听起来像是一个错误。我会整理一个重现案例并提交一个错误 bugbase.adobe.com .

虽然并不理想,但一种可能的解决方法是在格式化行之后设置日期列值。不幸的是,设置单元格值也会消除背景颜色,因此您还需要重新应用它。使用 CF11、YMMV 进行测试。

注意:解决方法根本不会改变列的顺序,只会在格式化列时。所以“日期”仍然在第一列中结束。

Runnable Example on TryCF.com

<cfscript>
    objSheet = SpreadSheetNew("Sheet1", true);
    for(iRow = 1; iRow <= 100; iRow++) {

        // populate everything EXCEPT the date column
        SpreadsheetSetCellValue(objSheet, "B", iRow, 2);
        SpreadsheetSetCellValue(objSheet, "C", iRow, 3);
        SpreadsheetSetCellValue(objSheet, "D", iRow, 4);
        SpreadsheetSetCellValue(objSheet, "1234", iRow, 5);

        isAlternateRow = (iRow MOD 2) EQ 0;
        rowColor = isAlternateRow ? 'yellow' : 'white';

        // format whole row 
        if (isAlternateRow) {
            SpreadsheetFormatRow(objSheet, { fgcolor = rowColor }, iRow);
        }

        // finally apply date and reformat that cell
        SpreadsheetSetCellValue(objSheet, now(), iRow, 1, 'date');
        SpreadSheetFormatCell(objSheet, { dataformat = 'mm-dd-yyyy', fgcolor = rowColor}, iRow, 1);
    }
</cfscript>

结果:

Results

关于excel - 电子表格函数将日期转换为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50335541/

相关文章:

javascript - 对象中的计算值 |斯韦尔特

vba - 使用 VBA 在工作簿文件夹中循环代码?

python - Xlsxwriter 中有 csv.DictWriter 吗?

python - 用 Pandas 搜索整个 Excel 工作表中的单词

Coldfusion 9 cfexchangecalendar 交换服务器 outlook 2007

google-sheets - 条件格式不适用于 Google 表格中的 'countif' 函数

mysql - 如何将我的 View 表转换成excel格式

coldfusion - 从图像流式传输 cfcontent?

forms - 何时何地对用户输入进行编码?

ruby-on-rails - 'roo' 中 Excel 未初始化常量中的名称错误