2018-08-21 02:46:21 +01:00
|
|
|
// Add image to table cell
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
|
|
|
import { Document, Media, Packer, Paragraph } from "../build";
|
|
|
|
|
|
|
|
const doc = new Document();
|
|
|
|
|
2019-03-18 23:50:21 +00:00
|
|
|
const table = doc.createTable({
|
|
|
|
rows: 4,
|
|
|
|
columns: 4,
|
|
|
|
});
|
2018-12-29 01:57:20 +00:00
|
|
|
table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
|
2018-08-21 02:46:21 +01:00
|
|
|
|
2018-10-23 00:31:51 +01:00
|
|
|
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
2019-06-23 22:36:01 +01:00
|
|
|
table.getCell(1, 1).addParagraph(new Paragraph(image));
|
2018-08-21 02:46:21 +01:00
|
|
|
|
|
|
|
const packer = new Packer();
|
|
|
|
|
|
|
|
packer.toBuffer(doc).then((buffer) => {
|
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|