diff --git a/lib/xlsx/xform/book/workbook-xform.js b/lib/xlsx/xform/book/workbook-xform.js index f8ebce597..20bc46a87 100644 --- a/lib/xlsx/xform/book/workbook-xform.js +++ b/lib/xlsx/xform/book/workbook-xform.js @@ -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 diff --git a/spec/integration/data/chart-sheet.xlsx b/spec/integration/data/chart-sheet.xlsx new file mode 100644 index 000000000..c8d7b3c01 Binary files /dev/null and b/spec/integration/data/chart-sheet.xlsx differ diff --git a/spec/integration/worksheet.spec.js b/spec/integration/worksheet.spec.js index 4d513aefe..f7aba7487 100644 --- a/spec/integration/worksheet.spec.js +++ b/spec/integration/worksheet.spec.js @@ -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); + }); + }); });