jquery
  • excel
  • number-formatting
  • 2016-12-01 47 views 0 likes 
    0

    我有一個reportDiv與表reportTbl包含報告數據。我使用下面的代碼將報告數據導出到excel文件。jquery導出表爲Excel - 數字格式問題

    //Place links for exporting data to excel file 
    var htmltable= $("#reportDiv").get(0); 
    var html = htmltable.outerHTML; 
    csvData = 'data:application/vnd.ms-excel;charset=UTF-8,' + encodeURIComponent(html); 
    
    var excelLink = $('<a />', { 
        id : "excelHref", 
        class:"exportHref", 
        href : csvData, 
        text : "Export Excel", 
        download:"BMR_"+quarter + ".xls" 
    }); 
    $('#aDiv').append(excelLink); 
    
    $("#excelHref").click(function(e){ 
         return true; 
    }); 
    

    報表數據已導出並下載。當我在Microsoft Office Excel 2007中打開它時,數字數據的數字格式似乎發生了變化。 HTML表格的值四捨五入到小數點後兩位。但是,excel消除了小數點後的零。例如,12.00顯示爲12,34.50顯示爲34.5。

    HTML表格報告的截圖:報告在Excel enter image description here

    我可以得到數字格式相同的HTML表格做什麼 enter image description here

    屏幕截圖?

    謝謝。

    回答

    2

    嘗試阿克塞爾裏希特的回答:

    <td style='mso-number-format:"#,##0.00"'>100.00</td> 
    

    參考:Exporting HTML table with correct format in Javascript

    相關問題