diff --git a/demo/32-merge-and-shade-table-cells.ts b/demo/32-merge-and-shade-table-cells.ts index 6fc7f867ec..3dca2423d4 100644 --- a/demo/32-merge-and-shade-table-cells.ts +++ b/demo/32-merge-and-shade-table-cells.ts @@ -287,6 +287,7 @@ const table7 = new Table({ }), new TableCell({ children: [new Paragraph("0,3")], + rowSpan: 3, }), ], }), @@ -296,9 +297,6 @@ const table7 = new Table({ children: [new Paragraph("1,0")], columnSpan: 2, }), - new TableCell({ - children: [new Paragraph("1,3")], - }), ], }), new TableRow({ @@ -311,9 +309,6 @@ const table7 = new Table({ children: [new Paragraph("2,2")], rowSpan: 2, }), - new TableCell({ - children: [new Paragraph("2,3")], - }), ], }), new TableRow({ diff --git a/src/file/table/table-row/table-row.spec.ts b/src/file/table/table-row/table-row.spec.ts index 03b8b2862e..e381056c3e 100644 --- a/src/file/table/table-row/table-row.spec.ts +++ b/src/file/table/table-row/table-row.spec.ts @@ -271,7 +271,8 @@ describe("TableRow", () => { }); expect(tableRow.columnIndexToRootIndex(8, true)).to.equal(5); - expect(() => tableRow.columnIndexToRootIndex(9, true)).to.throw(`cell 'columnIndex' should not great than 8`); + // for column 10, just place the new cell at the end of cell + expect(tableRow.columnIndexToRootIndex(10, true)).to.equal(5); }); }); }); diff --git a/src/file/table/table-row/table-row.ts b/src/file/table/table-row/table-row.ts index 320616e809..05ba1264a5 100644 --- a/src/file/table/table-row/table-row.ts +++ b/src/file/table/table-row/table-row.ts @@ -83,10 +83,14 @@ export class TableRow extends XmlComponent { let colIdx = 0; // Offset because properties is also in root. let rootIdx = 1; - const endRootIndex = allowEndNewCell ? this.root.length : this.root.length - 1; while (colIdx <= columnIndex) { - if (rootIdx > endRootIndex) { - throw new Error(`cell 'columnIndex' should not great than ${colIdx - 1}`); + if (rootIdx >= this.root.length) { + if (allowEndNewCell) { + // for insert verticalMerge CONTINUE at row end + return this.root.length; + } else { + throw new Error(`cell 'columnIndex' should not great than ${colIdx - 1}`); + } } const cell = this.root[rootIdx] as TableCell; rootIdx += 1;