question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

reading with option `cellDates: true` has wrong date values if original cell date was before 26th march 2018

See original GitHub issue

if cells with date value have an date before 03/25/2018 and loading xlsx file with option cellDates: true the loaded cells in worksheet are one day earlier than original date value.

it(‘with option cellDates: true XLSX should parse date correctly’, function() { var wb = X.read( fs.readFileSync(‘./test_files-bug-report/check-date-bug.xlsx’), {cellDates: true, type: TYPE} ); var ws = wb.Sheets[‘check-date-bug’]; assert(dateToString(ws.B46.v) === ‘2018-6-5’); // work assert(dateToString(ws.B37.v) === ‘2018-3-27’); // work assert(dateToString(ws.B36.v) === ‘2018-3-26’); // work assert(dateToString(ws.B35.v) === ‘2018-3-25’); // fail: ‘2018-3-24’ assert(dateToString(ws.B34.v) === ‘2018-3-24’); // fail: ‘2018-3-23’ assert(dateToString(ws.B3.v) === ‘2015-1-1’); // fail: ‘2014-12-31’ assert(dateToString(ws.B2.v) === ‘2014-1-1’); // fail: ‘2013-12-31’ });

There is a fork with added test that currently fail: fork-branch: https://github.com/pluederitz/js-xlsx/tree/bug-date-parsing-cell-dates-true added test: https://github.com/pluederitz/js-xlsx/blob/bug-date-parsing-cell-dates-true/test.js#L384-L410 added xlsx file: https://github.com/pluederitz/js-xlsx/blob/bug-date-parsing-cell-dates-true/test_files-bug-report/check-date-bug.xlsx

to check bug run added test:

git clone https://github.com/pluederitz/js-xlsx.git checkout bug-date-parsing-cell-dates-true npm install make ctestserv open browser on http://127.0.0.1:8000

2nd suite “bug-reports” contains test “with option cellDates: true XLSX should parse date correctly (also date before 26th of march 2018)”

added bug test also fail on running tests under node.js

npm test

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Coadacommented, Apr 6, 2020

I had the same issue, and ended up parsing it on my own:

function excelDateToISODateString(excelDateNumber) {
    return new Date(Math.round((excelDateNumber - 25569) * 86400 * 1000)).toISOString().substring(0, 10);
}

This is based on a Stackoverflow answer: https://stackoverflow.com/a/22352911/11599033

2reactions
g1r0commented, Mar 14, 2019

Workaround: use SSF library to convert raw excel number dates.

let workbook = XLSX.read(data, { type, cellDates: **false** });
const ws = workbook.Sheets[workbook.SheetNames[0]];
const dateMode = workbook.Workbook.WBProps.date1904;
let val = ws.B3.v;
XLSX.SSF.format('YYYY-MM-DD', val, { date1904: dateMode }));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Date in XLS sheet not parsing correctly - Stack Overflow
The trick is to pass the option 'cellDates: true' and then to just instantiate a date from the numbers value and it should...
Read more >
Excel DATE function with formula examples to calculate dates
The tutorial explains the syntax and uses of the Excel DATE function and provides formula examples for calculating dates.
Read more >
6 Ways to Fix Dates Formatted as Text in Excel
6 ways to fix dates formatted ast text in Excel, plus a bonus technique using Power Query to fix various formats.
Read more >
Use Conditional Formatting in Excel to Highlight Dates Before ...
For example, enter =A2<TODAY() if A2 is the first in the range of selected cells containing a date. Click Format. A dialog box...
Read more >
Date Format in Excel - How to Change & Custom Format?
Date before 1900 or after 9999 is identified as a text value by Excel. ... We may use the “Custom” option of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found