Allow creating Styles and assigning them to File.Styles

Closes #109
This commit is contained in:
Felipe Ochoa
2018-08-16 16:28:10 -04:00
parent e0d54d3af3
commit edce1bef92
3 changed files with 40 additions and 1 deletions

34
demo/demo27.ts Normal file
View File

@ -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!");
});

View File

@ -1,2 +1,3 @@
export * from "./document";
export * from "./document-attributes";
export * from "./body";

View File

@ -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;
}