Skip to content

Commit

Permalink
Merge pull request exceljs#1487 from FliegendeWurst/add-last-column
Browse files Browse the repository at this point in the history
Add lastColumn property (fixes exceljs#1453)
  • Loading branch information
Siemienik authored Oct 6, 2020
2 parents 624d72f + b6762d7 commit d76dc38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/doc/worksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
3 changes: 3 additions & 0 deletions spec/integration/gold.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {});
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/pr/test-pr-1487.spec.js
Original file line number Diff line number Diff line change
@@ -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
});

0 comments on commit d76dc38

Please sign in to comment.