导出到Excel不正确显示数字

use*_*867 2 coldfusion excel 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> 
Run Code Online (Sandbox Code Playgroud)

Lei*_*igh 7

如果要导出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>
Run Code Online (Sandbox Code Playgroud)


buc*_*ova 5

您可以在帐号前插入撇号.这将强制excel将数字(任何)数据视为文本.