Files
docx-js/demo/demo31.ts

33 lines
876 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";
2019-06-25 01:21:28 +01:00
import { Document, HeadingLevel, Packer, Paragraph, VerticalAlign, Table } from "../build";
2018-09-12 21:03:06 +01: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: 2,
columns: 2,
});
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
2018-09-12 21:03:06 +01:00
table
2018-09-13 01:54:37 +01:00
.getCell(1, 1)
2019-06-25 23:17:56 +01:00
.add(new Paragraph("This text should be in the middle of the cell"))
.setVerticalAlign(VerticalAlign.CENTER);
2018-09-12 21:03:06 +01:00
2019-06-25 23:17:56 +01:00
table.getCell(1, 0).add(
2019-06-25 01:21:28 +01:00
new Paragraph({
text:
"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",
heading: HeadingLevel.HEADING_1,
}),
);
2018-09-13 01:54:37 +01:00
2018-09-12 21:03:06 +01:00
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});