:fix: rowSpan continue cell should has the same border to the first row cell

This commit is contained in:
wangfengming
2020-06-20 20:20:22 +08:00
parent e8f92efe05
commit 3977c8ab3b
2 changed files with 33 additions and 7 deletions

View File

@ -2,7 +2,7 @@
// Also includes an example on how to center tables // Also includes an example on how to center tables
// Import from 'docx' rather than '../build' if you install from npm // Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs"; import * as fs from "fs";
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build"; import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build";
const doc = new Document(); const doc = new Document();
@ -209,14 +209,40 @@ const table5 = new Table({
}, },
}); });
const borders = {
top: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
bottom: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
left: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
right: {
style: BorderStyle.DASH_SMALL_GAP,
size: 1,
color: "red",
},
};
const table6 = new Table({ const table6 = new Table({
rows: [ rows: [
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
children: [new Paragraph("11")], borders,
children: [new Paragraph("11"), new Paragraph("21")],
rowSpan: 2,
}), }),
new TableCell({ new TableCell({
borders,
children: [new Paragraph("12")], children: [new Paragraph("12")],
}), }),
], ],
@ -224,18 +250,17 @@ const table6 = new Table({
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
children: [new Paragraph("21"), new Paragraph("31")], borders,
children: [new Paragraph("22"), new Paragraph("32")],
rowSpan: 2, rowSpan: 2,
}), }),
new TableCell({
children: [new Paragraph("22")],
}),
], ],
}), }),
new TableRow({ new TableRow({
children: [ children: [
new TableCell({ new TableCell({
children: [new Paragraph("32")], borders,
children: [new Paragraph("31")],
}), }),
], ],
}), }),

View File

@ -87,6 +87,7 @@ export class Table extends XmlComponent {
for (let i = rowIndex + 1; i <= endRowIndex; i++) { for (let i = rowIndex + 1; i <= endRowIndex; i++) {
rows[i].addCellToIndex( rows[i].addCellToIndex(
new TableCell({ new TableCell({
borders: cell.options.borders,
children: [], children: [],
verticalMerge: VerticalMergeType.CONTINUE, verticalMerge: VerticalMergeType.CONTINUE,
}), }),