diff --git a/demo/demo27.ts b/demo/demo27.ts new file mode 100644 index 0000000000..e04fc07e02 --- /dev/null +++ b/demo/demo27.ts @@ -0,0 +1,34 @@ +import * as fs from "fs"; +import { Document, Packer } from "../build"; + +const doc = new Document(); +const myStyles = doc.Styles; + +// The first argument is an ID you use to apply the style to paragraphs +// The second argument is a human-friendly name to show in the UI +myStyles.createParagraphStyle("myWonkyStyle", "My Wonky Style") + .basedOn("Normal") + .next("Normal") + .color("990000") + .italics() + .indent({left: 720}) // 720 TWIP === 720 / 20 pt === .5 in + .spacing({line: 276}); // 276 / 240 = 1.15x line spacing + +myStyles.createParagraphStyle("Heading2", "Heading 2") + .basedOn("Normal") + .next("Normal") + .quickFormat() + .size(26) // 26 half-points === 13pt font + .bold() + .underline("double", "FF0000") + .spacing({before: 240, after: 120}); // TWIP for both + +doc.createParagraph("Hello").style("myWonkyStyle"); +doc.createParagraph("World").heading2(); // Uses the Heading2 style + +const packer = new Packer(); + +packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); + console.log("Document created successfully at project root!"); +}); diff --git a/src/file/document/index.ts b/src/file/document/index.ts index 6b128299f6..3430666623 100644 --- a/src/file/document/index.ts +++ b/src/file/document/index.ts @@ -1,2 +1,3 @@ export * from "./document"; +export * from "./document-attributes"; export * from "./body"; diff --git a/src/file/file.ts b/src/file/file.ts index 472baf28b5..621918c37a 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -17,7 +17,7 @@ import { Table } from "./table"; export class File { private readonly document: Document; - private readonly styles: Styles; + private styles: Styles; private readonly coreProperties: CoreProperties; private readonly numbering: Numbering; private readonly media: Media; @@ -214,6 +214,10 @@ export class File { return this.styles; } + public set Styles(styles: Styles) { + this.styles = styles; + } + public get CoreProperties(): CoreProperties { return this.coreProperties; }