diff --git a/demo/demo28.ts b/demo/demo28.ts new file mode 100644 index 0000000000..b7eab7b919 --- /dev/null +++ b/demo/demo28.ts @@ -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); +}); diff --git a/demo/demo29.ts b/demo/demo29.ts new file mode 100644 index 0000000000..8a5bc3fc03 --- /dev/null +++ b/demo/demo29.ts @@ -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); +});