ColdFusion (9) 神秘地删除了字符“D”和“F”导出到 Microsoft Excel 时在数字之后 (2007)
以下是示例的一些代码片段:
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 中打开时,它只显示 ' 而不是字面化单元格。
这很奇怪;有人知道发生了什么吗?
Here's some code snippets for an example:
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");
and
<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)#"/>
The issue is that "4D" and "4F" (and not the others) lose the 'D' and 'F' and are formatted as a number.
I tried this:
formatText = StructNew();
formatText.dataformat="@";
SpreadsheetFormatColumns(theSheet,formatText,"1-10");
I verified that this set the format in Excel to "Text", but now I just see the number 4 in a Text-formatted cell! I also tried using the ' character, but when it opens in Excel, it just shows the ' instead of literalizing the cell.
This is rather strange; anybody have an idea about what's going?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
似乎解决方法是将单元格公式设置为文字“4D”。
我仍然不知道为什么会发生这种情况,但我的想法是 SpreadsheetAddRow() 和 SpreadsheetSetCell() 将 4D 和 4F 解释为数字,并将 D 和 F 以及代表 Double 和 的后缀解释为浮动,并在转换后将它们剥离。
您可以转至 https://bugbase.adobe.com/index.cfm 将错误提交给 Adobe。
It seems that a workaround is to set the cell formula to be the literal "4D".
I still don't know why this is happening, but my idea is that SpreadsheetAddRow() and SpreadsheetSetCell() are interpreting 4D and 4F as numeric and are interpreting the D and F and suffixes standing for Double and Float, and stripping them out after conversion.
You can submit the bug to Adobe by going to https://bugbase.adobe.com/index.cfm.
您应该尝试显式使用 D 字符代码
chr(68)
而不是“D”。You should try to use D char code explicitly
chr(68)
instead of "D".您可以尝试旧的电子表格技巧 - 回到 Lotus 时代 - 通过以单引号开始条目来将值强制转换为文本:
'4D
。You might try the old spreadsheet trick -- going back to Lotus days -- of coercing values to text by starting the entry with a single quote:
'4D
.我更新了相关堆栈问题中的代码以搜索字符(通过前置或附加到给定文本来使用)以隐藏此 ColdFusion 功能:
原来前置或附加不可打印字符 chr(127) 和 chr(160) 维护了 我提到的4F 或 4D
相关堆栈问题: cfspreadsheet 字母数字值以 d 结尾
I updated code from a related stack question to search for characters (to use by prepending or appending to the given text) to hide this ColdFusion feature:
Turns out prepending or appending nonprintable characters chr(127) and chr(160) maintain the presentation of 4F or 4D
Related stack question I mentioned: cfspreadsheet alphanumeric values ending in d