Skip to content

Commit d17b361

Browse files
authored
Merge pull request #466 from peakon/fix/unbreakChartsheet
Don't break when loading an Excel file containing a chartsheet
2 parents 3950e0e + fd0bf4c commit d17b361

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/xlsx/xform/book/workbook-xform.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,16 @@ utils.inherits(WorkbookXform, BaseXform, {
158158
return;
159159
}
160160
worksheet = model.worksheetHash['xl/' + rel.Target];
161-
worksheet.name = sheet.name;
162-
worksheet.id = sheet.id;
163-
worksheets[index++] = worksheet;
161+
// If there are "chartsheets" in the file, rel.Target will
162+
// come out as chartsheets/sheet1.xml or similar here, and
163+
// that won't be in model.worksheetHash.
164+
// As we don't have the infrastructure to support chartsheets,
165+
// we will ignore them for now:
166+
if (worksheet) {
167+
worksheet.name = sheet.name;
168+
worksheet.id = sheet.id;
169+
worksheets[index++] = worksheet;
170+
}
164171
});
165172

166173
// reconcile print areas
14 KB
Binary file not shown.

spec/integration/worksheet.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -630,4 +630,12 @@ describe('Worksheet', function() {
630630
});
631631
});
632632
});
633+
634+
it('Should not break when importing an Excel file that contains a chartsheet', function() {
635+
return new Excel.Workbook().xlsx.readFile(path.resolve(__dirname, 'data', 'chart-sheet.xlsx'))
636+
.then(function(workbook) {
637+
expect(workbook).to.have.property('worksheets');
638+
expect(workbook.worksheets).to.have.length(1);
639+
});
640+
});
633641
});

0 commit comments

Comments
 (0)