在将数据从数据库导出到 Excel 电子表格时,我很难让帐号正确显示。一家公司的帐号显示正确。然而,其他人没有。用户必须双击单元格才能看到整个帐号。我用谷歌搜索了这个问题,但我尝试过的解决方案都没有奏效。
<cfsetting enablecfoutputonly="Yes">
<cfsavecontent variable="sTest">
<cfoutput>
<table>
<tr><th align="center">ATTUID</th>
<th>Company Name</th>
<th align="center">Account Number </th>
<th align="center">Total Past Due Balance</th>
<th align="center">Date Sent</th>
</tr>
<cfloop query="returnQuery">
<tr><td>#attuid#</td>
<td>#companyname#</td>
<td>#AccountNum4#</td>
<td>#totalpastdue#</td>
<td>#dateformat(posted)# #timeformat(posted, "h:mm tt")#</td>
</tr>
</cfloop>
</table>
</cfoutput>
</cfsavecontent>
<cfcontent type="application/vnd.msexcel">
<cfheader name="Content-Disposition" value="inline; filename=export.xls">
<cfoutput>#sTest#</cfoutput>
最佳答案
如果您正在导出 html,您还可以使用 xml mso 架构属性将数字格式化为文本,而不更改实际的单元格值,即添加撇号。
<cfheader name="Content-Disposition" value="inline; filename=someFile.xls">
<cfcontent type="application/vnd.ms-excel">
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<body>
<table>
<tr>
<td style='mso-number-format:"\@";'>510074123456989</td>
</tr>
</table>
</body>
</html>
关于excel - 导出到 Excel 无法正确显示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3392590/