Search code examples
javascriptformatxlsx

Javascript XLSX module formating data


I would like to change the default value used by XLSX.

Let me explain, here is my code :

var XLSX = require("xlsx");

var workbook = XLSX.read(data, { type: "array" });
console.log(workbook.Sheets["Current positions"]);

Here is an extract from this log :

  C19: {
    t: 's',
    v: 'BE0974320526',
    r: '<t>BE0974320526</t>',
    h: 'BE0974320526',
    w: 'BE0974320526'
  },
  D19: { t: 'n', v: 0.0069, w: '0.69%' },
  E19: { t: 'n', v: 44511, w: '11/11/2021' },

Then I use :

var excelRows = XLSX.utils.sheet_to_row_object_array("Current positions");
console.log(excelRows)

And here is an extract from the log (in the same place as above)

'ISSUER SHARE ISIN code': 'BE0974320526',
'% OF ISSUED CAPITAL': 0.0069,
'POSITION DATE': 44511

The function clearly take the v key as parameter. So my issue is that I want to have the w key field and not the v key field taking into account during XLSX.utils.sheet_to_row_object_array.

For the exemple here :

  • not 0.0069 but '0.69%'
  • not 44511 but '11/11/2021'

I hope to be clear, Thanks for your help !


Solution

  • Solution is just to add the raw:false parameter like that:

    var excelRows = XLSX.utils.sheet_to_row_object_array("Current positions",{raw:false});