Skip to content

Commit

Permalink
add fix multiple print areas error test case
Browse files Browse the repository at this point in the history
  • Loading branch information
CTyrannosaurus committed Jul 30, 2023
1 parent 80aacf6 commit 24b435b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 3 additions & 8 deletions lib/xlsx/xform/book/workbook-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,16 @@ class WorkbookXform extends BaseXform {
const definedName = {
name: '_xlnm.Print_Area',
localSheetId: index,
ranges:[]
ranges: [],
};
sheet.pageSetup.printArea.split('&&').forEach(printArea => {
const printAreaComponents = printArea.split(':');
definedName.ranges.push(
`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`
);
definedName.ranges.push(`'${sheet.name}'!$${printAreaComponents[0]}:$${printAreaComponents[1]}`);
});
printAreas.push(definedName);
}

if (
sheet.pageSetup &&
(sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)
) {
if (sheet.pageSetup && (sheet.pageSetup.printTitlesRow || sheet.pageSetup.printTitlesColumn)) {
const ranges = [];

if (sheet.pageSetup.printTitlesColumn) {
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/pr/new/test-new-pr-17.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ExcelJS = verquire('exceljs');

// const NEW_TEST_17_XLSX_FILE_NAME = './spec/integration/data/test-new-pr-17.xlsx';

describe('new pr related issues', () => {
describe('new pr 17 serialize and deserialize multiple print areas on one worksheet', () => {
it('Multiple print areas can be correctly read to settings', async () => {
const wb = new ExcelJS.Workbook();
const ws = wb.addWorksheet('sheet');
const writePrintArea = 'A2:B5&&A7:B10&&A13:B17';
ws.pageSetup.printArea = writePrintArea;
// await wb.xlsx.writeFile(NEW_TEST_17_XLSX_FILE_NAME);
const buffer = await wb.xlsx.writeBuffer();
await wb.xlsx.load(buffer);
const worksheet = wb.getWorksheet('sheet');
const readPintArea = worksheet.pageSetup.printArea;
expect(writePrintArea).to.equal(readPintArea);
});
});
});

0 comments on commit 24b435b

Please sign in to comment.