Add more table demos

This commit is contained in:
Dolan
2018-09-12 21:03:06 +01:00
parent 11ce9a5206
commit f1b176670c
2 changed files with 44 additions and 0 deletions

18
demo/demo28.ts Normal file
View File

@ -0,0 +1,18 @@
// 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();
const table = doc.createTable(4, 4);
table
.getCell(2, 2)
.addContent(new Paragraph("This text should be in the middle of the cell"))
.CellProperties.setVerticalAlign(VerticalAlign.CENTER);
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});

26
demo/demo29.ts Normal file
View File

@ -0,0 +1,26 @@
// 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 } from "../build";
const doc = new Document();
const table = doc.createTable(2, 2);
table
.getCell(0, 0)
.addContent(new Paragraph("Hello"))
.setHorizontalSpan(2);
doc.createParagraph("Another table").heading2();
const table2 = doc.createTable(2, 3);
table2
.getCell(0, 0)
.addContent(new Paragraph("World"))
.setHorizontalSpan(3);
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});