2019-02-26 21:38:54 +00:00
|
|
|
// Multiple cells merging in the same table
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2019-06-25 01:21:28 +01:00
|
|
|
import { Document, Packer, Paragraph, Table } from "../build";
|
2019-02-26 21:38:54 +00:00
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
2019-06-25 01:21:28 +01:00
|
|
|
const table = new Table({
|
2019-03-18 23:50:21 +00:00
|
|
|
rows: 13,
|
|
|
|
columns: 6,
|
|
|
|
});
|
2019-06-25 01:21:28 +01:00
|
|
|
|
2019-02-26 21:38:54 +00:00
|
|
|
let row = 0;
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(row, 0).add(new Paragraph("0,0"));
|
|
|
|
table.getCell(row, 1).add(new Paragraph("0,1"));
|
|
|
|
table.getCell(row, 3).add(new Paragraph("0,3"));
|
|
|
|
table.getCell(row, 4).add(new Paragraph("0,4"));
|
2019-02-26 21:38:54 +00:00
|
|
|
table.getRow(row).mergeCells(4, 5);
|
|
|
|
table.getRow(row).mergeCells(1, 2);
|
|
|
|
row = 1;
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(row, 0).add(new Paragraph("1,0"));
|
|
|
|
table.getCell(row, 2).add(new Paragraph("1,2"));
|
|
|
|
table.getCell(row, 4).add(new Paragraph("1,4"));
|
2019-02-26 21:38:54 +00:00
|
|
|
table.getRow(row).mergeCells(4, 5);
|
|
|
|
table.getRow(row).mergeCells(2, 3);
|
|
|
|
table.getRow(row).mergeCells(0, 1);
|
|
|
|
|
|
|
|
row = 2;
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(row, 0).add(new Paragraph("2,0"));
|
|
|
|
table.getCell(row, 1).add(new Paragraph("2,1"));
|
|
|
|
table.getCell(row, 2).add(new Paragraph("2,2"));
|
|
|
|
table.getCell(row, 3).add(new Paragraph("2,3"));
|
|
|
|
table.getCell(row, 4).add(new Paragraph("2,4"));
|
2019-02-26 21:38:54 +00:00
|
|
|
table.getRow(row).mergeCells(4, 5);
|
|
|
|
table.getRow(row).mergeCells(1, 2);
|
|
|
|
row = 3;
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(row, 0).add(new Paragraph("3,0"));
|
|
|
|
table.getCell(row, 1).add(new Paragraph("3,1"));
|
|
|
|
table.getCell(row, 2).add(new Paragraph("3,2"));
|
|
|
|
table.getCell(row, 3).add(new Paragraph("3,3"));
|
|
|
|
table.getCell(row, 4).add(new Paragraph("3,4"));
|
|
|
|
table.getCell(row, 5).add(new Paragraph("3,5"));
|
2019-02-26 21:38:54 +00:00
|
|
|
row = 4;
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(row, 0).add(new Paragraph("4,0"));
|
|
|
|
table.getCell(row, 5).add(new Paragraph("4,5"));
|
2019-02-26 21:38:54 +00:00
|
|
|
table.getRow(row).mergeCells(0, 4);
|
|
|
|
|
2019-07-31 08:48:02 +01:00
|
|
|
doc.addSection({
|
|
|
|
children: [table],
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
});
|