Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mgcrea/node-xlsx
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcrea committed Jul 23, 2017
2 parents faf095a + 26f67bd commit db8f258
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -7,7 +7,7 @@ export function parse(mixed, options = {}) {
const workSheet = XLSX[isString(mixed) ? 'readFile' : 'read'](mixed, options);
return Object.keys(workSheet.Sheets).map((name) => {
const sheet = workSheet.Sheets[name];
return {name, data: XLSX.utils.sheet_to_json(sheet, {header: 1, raw: true})};
return {name, data: XLSX.utils.sheet_to_json(sheet, {header: 1, raw: options.raw !== false})};
});
}

Expand Down
31 changes: 31 additions & 0 deletions test/fixtures/dateField.json
@@ -0,0 +1,31 @@
[
{
"name": "Sheet1",
"data": [
[
"Serial 1",
"Serial 2",
"Serial 3",
"UPC",
"PO#",
"Date Received"
],
[
"SPKA19BD170C53",
"SPKA19BD170420",
"SPKA19BD1707F3",
"861453000227",
"10012",
"5/25/17"
],
[
"SPKA19BD16007A",
"SPKA19BD170927",
"SPKA19BD1702B9",
"861453000227",
"10012",
"5/25/17"
]
]
}
]
Binary file added test/fixtures/dateField.xlsx
Binary file not shown.
6 changes: 6 additions & 0 deletions test/specs/parse.spec.js
Expand Up @@ -18,4 +18,10 @@ describe('node-xlsx parser', () => {
const result = JSON.parse(JSON.stringify(parseXSLX(file)));
expect(result).toEqual(expected);
});
it('should properly parse an XLSX file with date field', () => {
const expected = JSON.parse(fs.readFileSync(`${__dirname}/../fixtures/dateField.json`));
const file = `${__dirname}/../fixtures/dateField.xlsx`;
const result = JSON.parse(JSON.stringify(parseXSLX(file, {raw: false})));
expect(result).toEqual(expected);
});
});

0 comments on commit db8f258

Please sign in to comment.