jquery
  • excel
  • number-formatting
  • 2016-12-01 52 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

    相关问题