Thara Thara - 8 months ago 62
jQuery Question

Jquery export table to excel - number format issue

I have a

with a table
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/;charset=UTF-8,' + encodeURIComponent(html);

var excelLink = $('<a />', {
id : "excelHref",
href : csvData,
text : "Export Excel",
download:"BMR_"+quarter + ".xls"

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?


Answer Source

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