Skip to content

Commit

Permalink
Merge pull request exceljs#1328 from mouse9/bug/date-parsing-issue
Browse files Browse the repository at this point in the history
bug fix can not read property date1904 of undefined
  • Loading branch information
Siemienik authored Jun 28, 2020
2 parents e2aab24 + 355dd72 commit b7df1c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/stream/xlsx/worksheet-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class WorksheetReader extends EventEmitter {

default:
if (utils.isDateFmt(cell.numFmt)) {
cell.value = utils.excelToDate(parseFloat(c.v.text), properties.model.date1904);
cell.value = utils.excelToDate(parseFloat(c.v.text), properties.model && properties.model.date1904);
} else {
cell.value = parseFloat(c.v.text);
}
Expand Down
Binary file added spec/integration/data/dateIssue.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ExcelJS = verquire('exceljs');
const fs = require('fs');


describe('github issues: Date field with cache style', () => {
const rows = [];
beforeEach(() =>
new Promise((resolve, reject) => {
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(fs.createReadStream('./spec/integration/data/dateIssue.xlsx'), { worksheets: 'emit', styles: 'cache', sharedStrings: 'cache', hyperlinks: 'ignore', entries: 'ignore' });
workbookReader.read();
workbookReader.on('worksheet', worksheet => worksheet.on('row', row => rows.push(row.values[1])));
workbookReader.on('end', resolve);
workbookReader.on('error', reject);

})
);
it('issue 1328 - should emit row with Date Object', () => {
expect(rows).that.deep.equals(['Date', new Date('2020-11-20T00:00:00.000Z')]);
});
});

0 comments on commit b7df1c5

Please sign in to comment.