:fix: insert the continue cell properly
This commit is contained in:
@ -79,25 +79,26 @@ export class Table extends XmlComponent {
|
||||
}
|
||||
|
||||
rows.forEach((row, rowIndex) => {
|
||||
row.cells.forEach((cell, cellIndex) => {
|
||||
if (rowIndex === rows.length - 1) {
|
||||
// don't process the end row
|
||||
return;
|
||||
}
|
||||
let columnIndex = 0;
|
||||
row.cells.forEach((cell) => {
|
||||
// Row Span has to be added in this method and not the constructor because it needs to know information about the column which happens after Table Cell construction
|
||||
// Row Span of 1 will crash word as it will add RESTART and not a corresponding CONTINUE
|
||||
if (cell.options.rowSpan && cell.options.rowSpan > 1) {
|
||||
const columnIndex = row.rootIndexToColumnIndex(cellIndex + 1);
|
||||
const startRowIndex = rowIndex + 1;
|
||||
const endRowIndex = rowIndex + (cell.options.rowSpan - 1);
|
||||
for (let i = startRowIndex; i <= endRowIndex; i++) {
|
||||
rows[i].addCellToColumnIndex(
|
||||
new TableCell({
|
||||
columnSpan: cell.options.columnSpan,
|
||||
borders: cell.options.borders,
|
||||
children: [],
|
||||
verticalMerge: VerticalMergeType.CONTINUE,
|
||||
}),
|
||||
columnIndex,
|
||||
);
|
||||
}
|
||||
const continueCell = new TableCell({
|
||||
// the inserted CONTINUE cell has rowSpan, and will be handled when process the next row
|
||||
rowSpan: cell.options.rowSpan - 1,
|
||||
columnSpan: cell.options.columnSpan,
|
||||
borders: cell.options.borders,
|
||||
children: [],
|
||||
verticalMerge: VerticalMergeType.CONTINUE,
|
||||
});
|
||||
rows[rowIndex + 1].addCellToColumnIndex(continueCell, columnIndex);
|
||||
}
|
||||
columnIndex += cell.options.columnSpan || 1;
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user