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.

[BUG] date parsing doesn't work in streaming mode

See original GitHub issue

🐛 Bug Report

Dates are not being parsed correctly when using streaming - issue seems to be the parser internally not getting the “style” for the field.

Lib version: 4.1.1 (latest)

Steps To Reproduce

const through = require('through2')
const { pipeline, Readable } = require('readable-stream')

const reader = new Excel.stream.xlsx.WorkbookReader(fs.createReadStream('file.xlsx'))
const createReader = async function* () {
  for await (const worksheet of reader) {
    for await (const row of worksheet) {
      yield row
    }
  }
}
  

const out = pipeline(
  Readable.from(createReader()),
  through.obj(function (row, _, cb) {
    console.log(row.values)
    cb(null, row)
  }),
  (err) => {
    if (err) out.emit('error', err)
  }
)

You’ll see the second column always comes back as a number, even though it should be an ISO string. This file is parsed perfectly fine and gives the correct results when not using streaming mode.

Attached the excel file, you can see the second column is properly date formatted.

file.xlsx

Possible solution

I debugged into the library, it seems like the issue is that this is always returning null and not finding the style, which means that later on when it checks the number format to see if it is a date it returns false and just treats it as a number. In the case of this excel sheet, c.s is 2 - so it could be that s is not being parsed right, because it looks like 2 in defaultnumformats.js = general number. I’ve tried changing to every other date format in excel and re-saving the file and it still comes back as 2 every time.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

5reactions
rheidaricommented, Sep 16, 2020

I had this issue as well, and it was due to me ignoring styles. The streaming reader has a second options parameter WorkbookStreamReaderOptions. The docs says it defaults to cache, but according to the type definition it defaults to ignore. https://github.com/exceljs/exceljs#streaming-xlsx-readercontents

new Excel.stream.xlsx.WorkbookReader(filePath, {
	entries: 'emit',
	sharedStrings: 'cache',
	hyperlinks: 'cache',
	styles: 'cache',
	worksheets: 'emit',
});
0reactions
yocontracommented, Dec 16, 2020

Quick update: There is a race condition with the streaming parser, depending on the ordering of the files in the excel zip it will start parsing the worksheet before the styles have been parsed and dates will just come in as numbers.

Specifically I’ve fixed it with this change: https://github.com/contra/exceljs/commit/457b0b35d54b5eea4c72d3c9fb53318e817083a0

I’ve run into a handful of race conditions, stalls and other issues with the streaming parser - once I have everything working perfectly I’ll send a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot parse String in ISO 8601 format, lacking colon in offset ...
I was trying to find Jackson configuration and DateTimeFormatter to parse "2018-02-13T10:20:12.120+0000" string to any Java 8 date, and didn't ...
Read more >
How we fixed a strange 'week year' bug
It's unusual for working code to suddenly break. Date and time formatting patterns. We were in the last few days of the year...
Read more >
8.2 Parsing HTML documents — HTML5 - W3C
If the encoding that is already being used to interpret the input stream is a UTF-16 encoding, then set the confidence to certain...
Read more >
Time formatting and storage bugs - Wikipedia
Language · Watch · Edit. In computer science, time formatting and storage bugs are a class of software bugs that may cause time...
Read more >
The 10 Most Common JavaScript Issues Developers Face
If you need help figuring out why your JavaScript isn't working, consult this ... While, admittedly, failing to use strict mode is not...
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