Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
536 views
in Technique[技术] by (71.8m points)

coldfusion - Export to Excel not displaying numbers correctly

I'm having a hard time getting account numbers to display correctly when exporting data from database to an Excel spreadsheet. The account number for one company, shows up correctly. However, others don't. Users have to double click in the cell to see the whole account number. I have Googled this issue and none of the solutions that I've tried worked.

<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> 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are exporting html, you could also use the xml mso schema properties to format the number as text, without changing the actual cell value ie adding an apostrophe.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...