2019-09-25 00:57:24 +01:00
|
|
|
// Multiple cells merging in the same table - Rows and Columns
|
2019-02-26 21:38:54 +00:00
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2019-09-13 00:51:20 +01:00
|
|
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
2019-02-26 21:38:54 +00:00
|
|
|
|
2019-06-25 01:21:28 +01:00
|
|
|
const table = new Table({
|
2019-09-13 00:51:20 +01:00
|
|
|
rows: [
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,1")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,4")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,0")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,2")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,4")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,1")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,4")],
|
|
|
|
columnSpan: 2,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,1")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,0")],
|
|
|
|
columnSpan: 5,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
2019-03-18 23:50:21 +00:00
|
|
|
});
|
2019-06-25 01:21:28 +01:00
|
|
|
|
2019-09-22 02:39:38 +01:00
|
|
|
const table2 = new Table({
|
|
|
|
rows: [
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,1")],
|
|
|
|
rowSpan: 2,
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("0,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("1,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,1")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("2,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,1")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("3,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,0")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,1")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,2")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,3")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,4")],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("4,5")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
new TableCell({
|
|
|
|
children: [],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const doc = new Document({
|
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
children: [table, new Paragraph(""), table2],
|
|
|
|
},
|
|
|
|
],
|
2019-07-31 08:48:02 +01:00
|
|
|
});
|
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2019-02-26 21:38:54 +00:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|