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";
|
2018-09-10 10:01:26 -03:00
|
|
|
import { File, Packer, Paragraph, TableOfContents } from "../build";
|
2018-09-04 11:03:17 -03:00
|
|
|
|
2018-09-10 10:01:26 -03:00
|
|
|
const doc = new File();
|
2018-09-04 11:03:17 -03:00
|
|
|
|
2018-09-04 12:05:41 -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();
|
|
|
|
|
2018-09-10 10:01:26 -03:00
|
|
|
// 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());
|
2018-09-10 10:01:26 -03:00
|
|
|
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());
|
2018-09-10 10:01:26 -03:00
|
|
|
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);
|
|
|
|
});
|