2

将数据从数据库导出到 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#‌​&lt;/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> 
4

3 回答 3

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>
于 2010-08-03T18:34:32.160 回答
5

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

于 2010-08-03T00:11:36.963 回答
1

这通常发生在列的宽度不足以显示数据时。尝试使列更宽,看看是否可以解决问题。

于 2010-08-03T00:11:31.207 回答