Skip to content

Commit 24b435b

Browse files
add fix multiple print areas error test case
1 parent 80aacf6 commit 24b435b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,16 @@ class WorkbookXform extends BaseXform {
4545
const definedName = {
4646
name: '_xlnm.Print_Area',
4747
localSheetId: index,
48-
ranges:[]
48+
ranges: [],
4949
};
5050
sheet.pageSetup.printArea.split('&&').forEach(printArea => {
5151
const printAreaComponents = printArea.split(':');
52-
definedName.ranges.push(
53-
`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`
54-
);
52+
definedName.ranges.push(`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`);
5553
});
5654
printAreas.push(definedName);
5755
}
5856

59-
if (
60-
sheet.pageSetup &&
61-
(sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)
62-
) {
57+
if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) {
6358
const ranges = [];
6459

6560
if (sheet.pageSetup.printTitlesColumn) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const ExcelJS = verquire('exceljs');
2+
3+
// const NEW_TEST_17_XLSX_FILE_NAME = './spec/integration/data/test-new-pr-17.xlsx';
4+
5+
describe('new pr related issues', () => {
6+
describe('new pr 17 serialize and deserialize multiple print areas on one worksheet', () => {
7+
it('Multiple print areas can be correctly read to settings', async () => {
8+
const wb = new ExcelJS.Workbook();
9+
const ws = wb.addWorksheet('sheet');
10+
const writePrintArea = 'A2:B5&&A7:B10&&A13:B17';
11+
ws.pageSetup.printArea = writePrintArea;
12+
// await wb.xlsx.writeFile(NEW_TEST_17_XLSX_FILE_NAME);
13+
const buffer = await wb.xlsx.writeBuffer();
14+
await wb.xlsx.load(buffer);
15+
const worksheet = wb.getWorksheet('sheet');
16+
const readPintArea = worksheet.pageSetup.printArea;
17+
expect(writePrintArea).to.equal(readPintArea);
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)