excel - 导出到 Excel 无法正确显示数字

标签 excel coldfusion export-to-excel coldfusion-8

在将数据从数据库导出到 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>#totalpastd‌​ue#</td>
              <td>#datefor‌​mat(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/

相关文章:

java - 无法在 Android 中创建 CSV 文件,总是失败

vba - 仿真在 10k 周期时运行良好,但在 100k 周期时出现错误 13(类型不匹配)

excel - ColdFusion 电子表格内存问题

java - 将单个 senerio 与 ANTLR 匹配并跳过其他所有噪音

c# - 如何将使用封闭的 xml 创建的 excel 文件转换为字节格式

apache-flex - 如何将数据网格导出到 Flex 中的 Excel 文件?

excel - 从全局地址簿中获取电话号码

mysql - 使用Excel连续连接和断开Mysql

excel - VBA循环结合Lastrow并查找空白值

apache - ColdFusion 9、Tomcat 7、Apache 和虚拟主机