From fe3dc24ed13dfae4cc35dde3d6fc043b81f9467d Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu@web.de> Date: Sun, 4 Oct 2020 12:39:07 +0200 Subject: [PATCH 1/2] Add lastColumn property (fixes #1453) --- lib/doc/worksheet.js | 4 ++++ spec/integration/gold.spec.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/doc/worksheet.js b/lib/doc/worksheet.js index 3bcfb377b..ce211348c 100644 --- a/lib/doc/worksheet.js +++ b/lib/doc/worksheet.js @@ -260,6 +260,10 @@ class Worksheet { this.workbook.definedNames.spliceColumns(this.name, start, count, inserts.length); } + get lastColumn() { + return this.getColumn(this.columnCount); + } + get columnCount() { let maxCount = 0; this.eachRow(row => { diff --git a/spec/integration/gold.spec.js b/spec/integration/gold.spec.js index 05473e721..c20d17931 100644 --- a/spec/integration/gold.spec.js +++ b/spec/integration/gold.spec.js @@ -31,6 +31,9 @@ describe('Gold Book', () => { hyperlink: 'https://www.npmjs.com/package/exceljs', text: 'exceljs', }); + + expect(ws.lastColumn).to.equal(ws.getColumn(2)); + expect(ws.lastRow).to.equal(ws.getRow(6)); }); it('Styles', () => {}); From b6762d78894fe98fe678c83f6eab755390d2ac3f Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu@web.de> Date: Mon, 5 Oct 2020 09:44:23 +0200 Subject: [PATCH 2/2] Add another test for lastColumn --- spec/integration/pr/test-pr-1487.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 spec/integration/pr/test-pr-1487.spec.js diff --git a/spec/integration/pr/test-pr-1487.spec.js b/spec/integration/pr/test-pr-1487.spec.js new file mode 100644 index 000000000..2070e8493 --- /dev/null +++ b/spec/integration/pr/test-pr-1487.spec.js @@ -0,0 +1,14 @@ +const ExcelJS = verquire('exceljs'); + +describe('github issues', () => { + describe('pull request 1487 - lastColumn with an empty column', () => { + it('Reading 1904.xlsx', () => { + const wb = new ExcelJS.Workbook(); + return wb.xlsx.readFile('./spec/integration/data/1904.xlsx').then(() => { + const ws = wb.getWorksheet('Sheet1'); + expect(ws.lastColumn).to.equal(ws.getColumn(2)); + }); + }); + }); + // the new property is also tested in gold.spec.js +});