From 31a91116674231815624542b99d95cbe7a64ed32 Mon Sep 17 00:00:00 2001 From: Travis Fletcher Date: Wed, 15 May 2019 18:14:39 -0400 Subject: [PATCH 1/2] Fix merging of 3+ cells vertically --- src/file/table/table-column.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/file/table/table-column.ts b/src/file/table/table-column.ts index b06a9f29a4..9fb3261502 100644 --- a/src/file/table/table-column.ts +++ b/src/file/table/table-column.ts @@ -15,7 +15,10 @@ export class TableColumn { public mergeCells(startIndex: number, endIndex: number): TableCell { this.cells[startIndex].addVerticalMerge(VMergeType.RESTART); - this.cells[endIndex].addVerticalMerge(VMergeType.CONTINUE); + + for (let i = startIndex; i <= endIndex; i++) { + this.cells[i].addVerticalMerge(VMergeType.CONTINUE); + } return this.cells[startIndex]; } From 3a593a53d3a95917a9d5f00168d19bed97349988 Mon Sep 17 00:00:00 2001 From: Travis Fletcher Date: Thu, 16 May 2019 11:15:20 -0400 Subject: [PATCH 2/2] Fix tests --- src/file/table/table-column.spec.ts | 4 +++- src/file/table/table-column.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/file/table/table-column.spec.ts b/src/file/table/table-column.spec.ts index eef7a2dfc9..aa031423a3 100644 --- a/src/file/table/table-column.spec.ts +++ b/src/file/table/table-column.spec.ts @@ -43,7 +43,9 @@ describe("TableColumn", () => { }); const tree2 = new Formatter().format(cells[1]); - expect(tree2).to.deep.equal({ "w:tc": [{ "w:p": EMPTY_OBJECT }] }); + expect(tree2).to.deep.equal({ + "w:tc": [{ "w:tcPr": [{ "w:vMerge": { _attr: { "w:val": "continue" } } }] }, { "w:p": EMPTY_OBJECT }], + }); const tree3 = new Formatter().format(cells[2]); expect(tree3).to.deep.equal({ diff --git a/src/file/table/table-column.ts b/src/file/table/table-column.ts index 9fb3261502..5752bde472 100644 --- a/src/file/table/table-column.ts +++ b/src/file/table/table-column.ts @@ -16,7 +16,7 @@ export class TableColumn { public mergeCells(startIndex: number, endIndex: number): TableCell { this.cells[startIndex].addVerticalMerge(VMergeType.RESTART); - for (let i = startIndex; i <= endIndex; i++) { + for (let i = startIndex + 1; i <= endIndex; i++) { this.cells[i].addVerticalMerge(VMergeType.CONTINUE); }