简体   繁体   中英

Retain decimal seperator on export excel in Datatables

This is my values that I am getting in datatable.

Cuenta  Nombre Cuenta       Oct18   Dec18   Sep19   Oct19   M$      M%  A$      A%
11      Activos Liquidos    5732,12 6950,89 5879,21 5965,02 85,82   1.4 232,91  4.06   

When exporting the excel the data's decimal place gets converted to 5732.12 6950.89..etc. I need to preserve the decimal I am using datatables.

I used this code:

{
      extend: 'excel',
      exportOptions: {
          columns: ':visible',
          format: {
              body: function(data, row, column, node) {
                  data = $('<p>' + data + '</p>').text();
                  return $.isNumeric(data.replace(',', '.')) ? data.replace(',', '.') : data;
              }
          }
      }
  }

But it changes my 4.06 to 4,06 which is incorrect. How to achieve this? Thank you.

Update:

This is the value I am getting in excel

这就是我得到的,但完全错误

Does this help?

 const fields = "11\tActivos Liquidos\t5732,12\t6950,89\t5879,21\t5965,02\t85,82\t1.4\t232,91\t4.06".trim().split("\t").map(fld => /^\d/.test(fld)? parseFloat(fld.replace(/,/,".")): fld); console.log(JSON.stringify(fields))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM