Skip to content

Commit

Permalink
Merge pull request #466 from peakon/fix/unbreakChartsheet
Browse files Browse the repository at this point in the history
Don't break when loading an Excel file containing a chartsheet
  • Loading branch information
guyonroche authored Jan 16, 2018
2 parents 3950e0e + fd0bf4c commit d17b361
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,16 @@ utils.inherits(WorkbookXform, BaseXform, {
return;
}
worksheet = model.worksheetHash['xl/' + rel.Target];
worksheet.name = sheet.name;
worksheet.id = sheet.id;
worksheets[index++] = worksheet;
// If there are "chartsheets" in the file, rel.Target will
// come out as chartsheets/sheet1.xml or similar here, and
// that won't be in model.worksheetHash.
// As we don't have the infrastructure to support chartsheets,
// we will ignore them for now:
if (worksheet) {
worksheet.name = sheet.name;
worksheet.id = sheet.id;
worksheets[index++] = worksheet;
}
});

// reconcile print areas
Expand Down
Binary file added spec/integration/data/chart-sheet.xlsx
Binary file not shown.
8 changes: 8 additions & 0 deletions spec/integration/worksheet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,12 @@ describe('Worksheet', function() {
});
});
});

it('Should not break when importing an Excel file that contains a chartsheet', function() {
return new Excel.Workbook().xlsx.readFile(path.resolve(__dirname, 'data', 'chart-sheet.xlsx'))
.then(function(workbook) {
expect(workbook).to.have.property('worksheets');
expect(workbook.worksheets).to.have.length(1);
});
});
});

0 comments on commit d17b361

Please sign in to comment.