Files
docx-js/demo/demo31.ts

27 lines
820 B
TypeScript
Raw Normal View History

2018-09-12 21:03:06 +01:00
// Example of how you would create a table and add data to it
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph, VerticalAlign } from "../build";
const doc = new Document();
2018-09-13 01:54:37 +01:00
const table = doc.createTable(2, 2);
2018-09-12 21:03:06 +01:00
table
2018-09-13 01:54:37 +01:00
.getCell(1, 1)
2018-09-12 21:03:06 +01:00
.addContent(new Paragraph("This text should be in the middle of the cell"))
.CellProperties.setVerticalAlign(VerticalAlign.CENTER);
2018-09-13 01:54:37 +01:00
table
.getCell(1, 0)
.addContent(
new Paragraph(
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
).heading1(),
);
2018-09-12 21:03:06 +01:00
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});