Skip to content

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

@yocontra

Description

@yocontra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions