dateNF seems to be ignored
See original GitHub issueHey there,
First of all, I’ve prepared a minimal demo of the issue I’m running into. You can find it here: https://github.com/pkaske/xlsx-date-issue
You should just need to clone
, npm install
and node ./index.js
it to reproduce.
Input data
input.xlsx
contains the following data:
The date format you see here is German (DD.MM.YYYY).
The cells are formated as dates in excel (2010).
What I want to accomplish
I want to convert that table to CSV and keep the date format as it is displayed in the screenshot (DD.MM.YYY).
This is what I tried
const stream = XLSX.stream.to_csv(worksheet, {
FS: ';',
RS: '\n',
dateNF: 'dd.mm.yyyy', // <--- Seems to be ignored.
strip: false,
blankrows: true
});
stream.pipe(Fs.createWriteStream(output))
.on('finish', () => {
console.log(output, 'written');
});
The actual output is
Name;Date
Person 1;12/31/18
Person 2;2/13/18
Person 3;4/5/18
Expected output
The dates should read 31.12.2018
, 13.02.2018
and 05.04.2018
.
Hopefully I just did something silly and that’s all 😃
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Developers - dateNF seems to be ignored - - Bountysource
Hey there,. First of all, I've prepared a minimal demo of the issue I'm running into. You can find it here: https://github.com/pkaske/xlsx-date-issue.
Read more >SheetJs converting date automatically angular 7
I'm using sheetjs in angular 7. And I'm exporting excel from my json. But excel converting my date to 02/29/2019 format. But, I'm...
Read more >Working with Dates and Time - XlsxWriter - Read the Docs
Dates and times in Excel are represented by real numbers, for example “Jan 1 2013 12:00 PM” is represented by the number 41275.5....
Read more >xlsx - npm
They are ignored by the core library data processing utility functions. ... To get around this ambiguity, parse functions accept the dateNF ......
Read more >@willyelm/jsexcel - npm Package Health Analysis | Snyk
They are ignored by the core library data processing utility functions. ... To get around this ambiguity, parse functions accept the dateNF ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sonjadeissenboeck regarding https://github.com/SheetJS/js-xlsx/issues/718#issuecomment-430628199, having same situation.
For me, it helped to work with the formatting in the data reading:
And you leave the
XLSX.utils.sheet_to_json({ raw: false })
Both of us did something silly 😃
tl;dr:
How does Excel handle international dates?
Excel dates are somewhat hokey. In the file, if you unzip and take a peek at
xl/worksheets/sheet1.xml
you’ll see entries likeThe reader has to figure out that the number corresponds to a date and convert it back. To do that it looks at the cell format from
xl/styles.xml
:All it stores is the number 14. Based in new york, your file looks like:
By fiddling with the regional settings, the same exact file will be displayed differently. https://github.com/SheetJS/js-xlsx/issues/326#issuecomment-286014758 is one comment showing a few different regional setting screenshots against Excel 95
What you should do
To override the date format, you must force the reader to ignore the original number format and force the writer to use a valid cell format.
On the read side, the line should be:
the
cellText:false
option skips generation of the original strings (thew
field is omitted) andcellDates:true
forces generation of date objects for cells that are possibly dates (instead of the file’s number values). After doing this, the worksheet date cells look like:On the write side, you need to quote the periods:
Why are quotes required in the date format?
The format displayed in the UI is not necessarily the same as the format displayed in the file. I took your file and changed one of the cells to follow the
dd.mm.yyyy
format in the UI. When saving the file, the actual format entry looks like:Excel is automagically fixing the decimal points as literal. The double quotes achieve the same effect.
What we should be doing