Using js-xlsx I did several attempts to write a XLSX file with a Date column, such as the one below. Each time, the date is not rendered as I expect when I open the XLSX file with Excel 2010: it is rendered as the number of days from a certain origin. Is there a way to render a date directly, without having to format the column in Excel ?
const XLSX = require("xlsx");
var wb = {
Sheets: {
Sheet1: {
'!ref': 'A1:A2',
A1: { t: 'd', v: new Date('13 April 2014 00:00 UTC'), w: '2014-04-13' },
A2: { t: 'd', v: new Date('13 April 2014 00:00 UTC'), w: '2014-04-13' }
}
},
SheetNames: [ 'Sheet1' ]
}
XLSX.writeFile(wb, "wbDate.xlsx", {cellDates: true});
Edit: possible answer
Finally I get some dates as follows:
const XLSX = require("xlsx");
var wb = {
Sheets: {
Sheet1: {
'!ref': 'A1:B2',
A1: { t: 'd', v: '2016-06-21' },
A2: { t: 'd', v: '2016-11-22' },
B1: { t: 'n', v: 42542, z: 'm/d/yy' },
B2: { t: 'n', v: 42696, z: 'm/d/yy' }
}
},
SheetNames: [ 'Sheet1' ]
}
XLSX.writeFile(wb, "wbDate.xlsx", {cellDates: false});
This gives (Windows 7, Excel 2010, locale time French Belgium):
Oddly, the format is given as m/d/yy
, but the output is rendered as d/m/yy
(or dd/mm/yy
?). I have not managed to get another format (but this one is nice for me).