2019-03-04 22:50:04 +00:00
|
|
|
// Add image to table cell
|
|
|
|
// 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-03-04 22:50:04 +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: 4,
|
|
|
|
columns: 4,
|
|
|
|
});
|
2019-06-25 01:21:28 +01:00
|
|
|
|
2019-06-25 23:17:56 +01:00
|
|
|
doc.add(table);
|
2019-06-25 01:21:28 +01:00
|
|
|
|
2019-06-25 23:17:56 +01:00
|
|
|
table.getCell(2, 2).add(new Paragraph("Hello"));
|
2019-03-04 22:50:04 +00:00
|
|
|
table.getColumn(3).mergeCells(1, 2);
|
2019-06-25 23:17:56 +01:00
|
|
|
// table.getCell(3, 2).add(new Paragraph("Hello"));
|
2019-03-04 22:50:04 +00:00
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|