2010-08-02 90 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