exceljs / exceljs/exceljs

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

Open
#1,430 12 comments 5 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
15.5k
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 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

```javascript
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](https://github.com/exceljs/exceljs/files/5087163/file.xlsx)

## Possible solution

I debugged into the library, it seems like the issue is that [this](https://github.com/exceljs/exceljs/blob/master/lib/stream/xlsx/worksheet-reader.js#L278) 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.