2010-08-02 86 views
2

我很难在将数据从数据库导出到Excel电子表格时正确显示帐号。一家公司的帐号正确显示。但是,其他人没有。用户必须双击单元格以查看整个帐号。我已经Google了这个问题,并没有我尝试过的解决方案。导出到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> 
+0

你是怎么做出口的?使用CF9电子表格功能,html(即psuedo-excel),...? – Leigh 2010-08-03 12:47:40

+0

​​#attuid#​​#公司名称#​​#AccountNum4#​​#totalpastdue#​​#dateformat(posted)##timeformat(posted,“h:mm t T “)#
ATTUID公司名称帐号总逾期平衡发送
user281867 2010-08-03 16:16:42

+0

这里是输出。 #sTest# user281867 2010-08-03 16:17:08

回答

5

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

+0

嗨巴波娃,谢谢你的回应。明天早上我会尝试你的建议。 – user281867 2010-08-03 04:50:04

+0

它的工作原理,感谢您的建议Buckbova! – user281867 2010-08-03 16:29:58

1

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

+0

嗨戴夫,我也会在明天早上试试你的请求。感谢您的答复! – user281867 2010-08-03 04:50:45

+0

嗨戴夫,这不适合我。感谢您的建议。 – user281867 2010-08-03 16:30:48

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> 
+0

谢谢,这对我有用! :)(和撇号解决方案没有)http://stackoverflow.com/questions/6737548/how-can-i-ensure-that-my-excel-cell-will-be-treated-as-a-string – froadie 2011-07-18 19:10:27