demo27 for TableOfContents
This commit is contained in:
26
demo/demo27.ts
Normal file
26
demo/demo27.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// 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 { Document, Packer, Paragraph, TableOfContents } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
// Creates an table of contents with default properties
|
||||||
|
const toc = new TableOfContents();
|
||||||
|
|
||||||
|
// The class TableOfContents extends Paragraph and can be added as such.
|
||||||
|
doc.addParagraph(toc)
|
||||||
|
|
||||||
|
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 little text very nicely written.'"));
|
||||||
|
doc.addParagraph(new Paragraph("Header #2.1").heading2());
|
||||||
|
doc.addParagraph(new Paragraph("I'm a little text very nicely written.'"));
|
||||||
|
|
||||||
|
const packer = new Packer();
|
||||||
|
|
||||||
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -6,4 +6,5 @@ export * from "./media";
|
|||||||
export * from "./drawing";
|
export * from "./drawing";
|
||||||
export * from "./document";
|
export * from "./document";
|
||||||
export * from "./styles";
|
export * from "./styles";
|
||||||
|
export * from "./table-of-contents";
|
||||||
export * from "./xml-components";
|
export * from "./xml-components";
|
||||||
|
Reference in New Issue
Block a user