Thara Thara - 4 days ago 4
jQuery Question

Jquery export table to excel - number format issue

I have a

reportDiv
with a table
reportTbl
that contains report data. I use the following code for exporting the report data to an excel file.

//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;
});


The report data was exported and downloaded. When I open it in Microsoft Office Excel 2007, the number format of numerical data seems to be changed. The HTML table has values rounded to two decimal places. But the excel eliminates zeros in decimal places. For example, 12.00 is shown as 12 and 34.50 is shown as 34.5.

Screenshot of report in html table:
enter image description here

Screen shot of report in excel
enter image description here

What can I do for getting the number format the same as in html table?

Thanks.

Answer

Try the answer of Axel Richter :

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

Reference: Exporting HTML table with correct format in Javascript

Comments