当导出到Microsoft Excel(2007)时,ColdFusion(9)在数字后神奇地移除字符“D”和“F”

以下是一些示例代码片段:

theSheet = SpreadsheetNew("Rates","True"); SpreadsheetAddRow(theSheet,"4A,4B,4C,4D,4E,4F,4G,4H,4I,4J"); SpreadsheetAddRow(theSheet,"4K,4L,4M,4N,4O,4P,4Q,4R,4S,4T"); SpreadsheetAddRow(theSheet,"4U,4V,4W,4X,4Y,4Z,4D4,4F4"); 

 <cfheader name="content-disposition" value="attachment; filename=#GetTickCount()#.xlsx"> <CFHEADER NAME="Expires" VALUE="#now()#"> <cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" variable="#SpreadsheetReadBinary(theSheet)#"/> 

问题是“4D”和“4F”(而不是其他)丢失了“D”和“F”,并被格式化为一个数字。

我试过这个:

 formatText = StructNew(); formatText.dataformat="@"; SpreadsheetFormatColumns(theSheet,formatText,"1-10"); 

我证实,这将Excel中的格式设置为“文本”,但现在我只是在文本格式的单元格中看到数字4! 我也尝试过使用'字符,但是当它在Excel中打开时,它只是显示'而不是字面化单元格。

这很奇怪, 有人有什么想法?

看起来解决方法是将单元格公式设置为文字“4D”。

 theSheet = SpreadsheetNew("Rates","True"); SpreadsheetAddRow(theSheet,"4A,4B,4C,,4E,,4G,4H,4I,4J"); SpreadsheetSetCellFormula(theSheet, """4D""", 1, 4); SpreadsheetSetCellFormula(theSheet, """4F""", 1, 6); SpreadsheetAddRow(theSheet,"4K,4L,4M,4N,4O,4P,4Q,4R,4S,4T"); SpreadsheetAddRow(theSheet,"4U,4V,4W,4X,4Y,4Z,4D4,4F4"); 

我仍然不知道为什么会发生这种情况,但我的想法是,SpreadsheetAddRow()和SpreadsheetSetCell()将4D和4F解释为数字,并解释D和F以及表示Double和Float的后缀,并将其解除转换。

您可以通过访问https://bugbase.adobe.com/index.cfm将错误提交给Adobe&#x3002;

您应该尝试显式地使用D char代码chr(68)而不是“D”。

您可以尝试使用旧的电子表格技巧 – 回到Lotus天 – 通过用单引号开始条目来强制值为文本: '4D

我更新了相关堆栈问题中的代码来search字符(通过预先添加或附加到给定的文本来使用)以隐藏此ColdFusionfunction:

 WorkBook = spreadsheetNew('Test', true); RowNumber = 1; for (i = 1; i <= 255; i++){ SpreadSheetSetCellValue(WorkBook, i, RowNumber, 1); // what character are we displaying SpreadSheetSetCellValue(WorkBook, chr(i), RowNumber, 2); // see if appending chr(i) allows 4F to display SpreadSheetSetCellValue(WorkBook, "4F#chr(i)#", RowNumber, 3); // see if appending chr(i) allows 4F to display SpreadSheetSetCellValue(WorkBook, "#chr(i)#4F", RowNumber, 4); RowNumber ++; } 

结果是前置或附加不可打印的字符chr(127)和chr(160)保持4F或4D的显示

我提到的相关堆栈问题: 以d结尾的cfspreadsheet字母数字值