Files
docx-js/demo/43-images-to-table-cell-2.ts

86 lines
2.1 KiB
TypeScript
Raw Normal View History

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-09-13 00:51:20 +01:00
import { Document, Packer, Paragraph, Table, TableCell, TableRow } 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-09-13 00:51:20 +01:00
rows: [
new TableRow({
children: [
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
],
}),
new TableRow({
children: [
new TableCell({
children: [],
}),
new TableCell({
children: [],
}),
new TableCell({
children: [new Paragraph("Hello")],
}),
new TableCell({
children: [],
}),
],
}),
new TableRow({
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-03-04 22:50:04 +00:00
table.getColumn(3).mergeCells(1, 2);
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [table],
});
2019-03-04 22:50:04 +00:00
2019-08-07 22:12:14 +01:00
Packer.toBuffer(doc).then((buffer) => {
2019-03-04 22:50:04 +00:00
fs.writeFileSync("My Document.docx", buffer);
});