Files
docx-js/demo/demo27.ts

29 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-04 11:03:17 -03:00
// Creates two paragraphs, one with a border and one without
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { File, Packer, Paragraph, TableOfContents } from "../build";
2018-09-04 11:03:17 -03:00
const doc = new File();
2018-09-04 11:03:17 -03:00
// WordprocessingML docs for TableOfContents can be found here:
// http://officeopenxml.com/WPtableOfContents.php
2018-09-04 11:03:17 -03:00
// Creates an table of contents with default properties
const toc = new TableOfContents();
// A TableOfContents must be added via File class.
doc.addTableOfContents(toc)
2018-09-04 11:03:17 -03:00
doc.addParagraph(new Paragraph("Header #1").heading1().pageBreakBefore());
doc.addParagraph(new Paragraph("I'm a little text very nicely written.'"));
doc.addParagraph(new Paragraph("Header #2").heading1().pageBreakBefore());
doc.addParagraph(new Paragraph("I'm a other text very nicely written.'"));
2018-09-04 11:03:17 -03:00
doc.addParagraph(new Paragraph("Header #2.1").heading2());
doc.addParagraph(new Paragraph("I'm a another text very nicely written.'"));
2018-09-04 11:03:17 -03:00
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});