32
demo/demo29.ts
Normal file
32
demo/demo29.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Indent, Numbering, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document();
|
||||||
|
|
||||||
|
const numbering = new Numbering();
|
||||||
|
|
||||||
|
const abstractNum = numbering.createAbstractNumbering();
|
||||||
|
abstractNum.createLevel(0, "upperRoman", "%1", "start").addParagraphProperty(new Indent({ left: 720, hanging: 260 }));
|
||||||
|
|
||||||
|
const concrete = numbering.createConcreteNumbering(abstractNum);
|
||||||
|
|
||||||
|
const item1 = new Paragraph("line with contextual spacing");
|
||||||
|
const item2 = new Paragraph("line with contextual spacing");
|
||||||
|
const item3 = new Paragraph("line without contextual spacing");
|
||||||
|
const item4 = new Paragraph("line without contextual spacing");
|
||||||
|
|
||||||
|
item1.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
||||||
|
item2.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(true);
|
||||||
|
item3.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
||||||
|
item4.setNumbering(concrete, 0).spacing({before: 200}).contextualSpacing(false);
|
||||||
|
|
||||||
|
doc.addParagraph(item1);
|
||||||
|
doc.addParagraph(item2);
|
||||||
|
doc.addParagraph(item3);
|
||||||
|
doc.addParagraph(item4);
|
||||||
|
|
||||||
|
const packer = new Packer();
|
||||||
|
|
||||||
|
packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -1,5 +1,5 @@
|
|||||||
// http://officeopenxml.com/WPspacing.php
|
// http://officeopenxml.com/WPspacing.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { Attributes, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export interface ISpacingProperties {
|
export interface ISpacingProperties {
|
||||||
after?: number;
|
after?: number;
|
||||||
@ -23,3 +23,14 @@ export class Spacing extends XmlComponent {
|
|||||||
this.root.push(new SpacingAttributes(opts));
|
this.root.push(new SpacingAttributes(opts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ContextualSpacing extends XmlComponent {
|
||||||
|
constructor(value: boolean) {
|
||||||
|
super("w:contextualSpacing");
|
||||||
|
this.root.push(
|
||||||
|
new Attributes({
|
||||||
|
val: value === false ? 0 : 1,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ import { Border, ThematicBreak } from "./formatting/border";
|
|||||||
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
|
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
|
||||||
import { KeepLines, KeepNext } from "./formatting/keep";
|
import { KeepLines, KeepNext } from "./formatting/keep";
|
||||||
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
|
import { PageBreak, PageBreakBefore } from "./formatting/page-break";
|
||||||
import { ISpacingProperties, Spacing } from "./formatting/spacing";
|
import { ContextualSpacing, ISpacingProperties, Spacing } from "./formatting/spacing";
|
||||||
import { Style } from "./formatting/style";
|
import { Style } from "./formatting/style";
|
||||||
import { CenterTabStop, LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
import { CenterTabStop, LeaderType, LeftTabStop, MaxRightTabStop, RightTabStop } from "./formatting/tab-stop";
|
||||||
import { NumberProperties } from "./formatting/unordered-list";
|
import { NumberProperties } from "./formatting/unordered-list";
|
||||||
@ -211,6 +211,11 @@ export class Paragraph extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public contextualSpacing(value: boolean): Paragraph {
|
||||||
|
this.properties.push(new ContextualSpacing(value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public keepNext(): Paragraph {
|
public keepNext(): Paragraph {
|
||||||
this.properties.push(new KeepNext());
|
this.properties.push(new KeepNext());
|
||||||
return this;
|
return this;
|
||||||
|
Reference in New Issue
Block a user