Files
docx-js/demo/demo32.ts

36 lines
1.0 KiB
TypeScript
Raw Normal View History

2018-12-29 01:57:20 +00:00
// Example of how you would merge cells together
2018-09-12 21:03:06 +01:00
// 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();
2018-10-15 21:54:33 +01:00
let table = doc.createTable(2, 2);
2018-12-29 01:57:20 +00:00
table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
2018-10-15 21:54:33 +01:00
table.getRow(0).mergeCells(0, 1);
2018-09-12 21:03:06 +01:00
doc.createParagraph("Another table").heading2();
2018-10-15 21:54:33 +01:00
table = doc.createTable(2, 3);
2018-12-29 01:57:20 +00:00
table.getCell(0, 0).addParagraph(new Paragraph("World"));
2018-10-15 21:54:33 +01:00
table.getRow(0).mergeCells(0, 2);
2018-09-12 21:03:06 +01:00
2018-09-13 01:54:37 +01:00
doc.createParagraph("Another table").heading2();
2018-10-15 21:54:33 +01:00
table = doc.createTable(2, 4);
2018-12-29 01:57:20 +00:00
table.getCell(0, 0).addParagraph(new Paragraph("Foo"));
2018-09-13 01:54:37 +01:00
2019-03-08 01:09:21 +00:00
// table.getCell(1, 0).addParagraph(new Paragraph("Bar1"));
// table.getCell(1, 1).addParagraph(new Paragraph("Bar2"));
// table.getCell(1, 2).addParagraph(new Paragraph("Bar3"));
// table.getCell(1, 3).addParagraph(new Paragraph("Bar4"));
2018-09-13 01:54:37 +01:00
2019-03-08 01:09:21 +00:00
// table.getRow(0).mergeCells(0, 3);
2018-10-15 21:54:33 +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);
});