added page break
This commit is contained in:
24
ts/docx/paragraph/border.ts
Normal file
24
ts/docx/paragraph/border.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
|
||||
class Border implements XmlComponent {
|
||||
private bottom: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.bottom = new Array<XmlComponent>();
|
||||
this.bottom.push(new Attributes({
|
||||
color: "auto",
|
||||
space: "1",
|
||||
val: "single",
|
||||
sz: "6"
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class ThematicBreak {
|
||||
private pBdr: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.pBdr = new Array<XmlComponent>();
|
||||
this.pBdr.push(new Border());
|
||||
}
|
||||
}
|
105
ts/docx/paragraph/index.ts
Normal file
105
ts/docx/paragraph/index.ts
Normal file
@ -0,0 +1,105 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
import {ThematicBreak} from "./border";
|
||||
import {PageBreak} from "./page-break";
|
||||
import {TextRun} from "./text-run";
|
||||
import {ParagraphProperties} from "./properties";
|
||||
|
||||
class Style {
|
||||
private pStyle: Array<XmlComponent>;
|
||||
|
||||
constructor(type: string) {
|
||||
this.pStyle = new Array<XmlComponent>();
|
||||
this.pStyle.push(new Attributes({
|
||||
val: type
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
class Alignment {
|
||||
private jc: Array<XmlComponent>;
|
||||
|
||||
constructor(type: string) {
|
||||
this.jc = new Array<XmlComponent>();
|
||||
this.jc.push(new Attributes({
|
||||
val: type
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export class Paragraph {
|
||||
private p: Array<XmlComponent>;
|
||||
private properties: ParagraphProperties;
|
||||
|
||||
constructor(text?: string) {
|
||||
this.p = new Array<XmlComponent>();
|
||||
this.p.push(new Attributes());
|
||||
this.properties = new ParagraphProperties();
|
||||
this.p.push(this.properties);
|
||||
this.p.push(new TextRun(text));
|
||||
}
|
||||
|
||||
addText(run: TextRun) {
|
||||
this.p.push(run);
|
||||
return this;
|
||||
}
|
||||
|
||||
heading1() {
|
||||
this.properties.push(new Style("Heading1"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading2() {
|
||||
this.properties.push(new Style("Heading2"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading3() {
|
||||
this.properties.push(new Style("Heading3"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading4() {
|
||||
this.properties.push(new Style("Heading4"));
|
||||
return this;
|
||||
}
|
||||
|
||||
heading5() {
|
||||
this.properties.push(new Style("Heading5"));
|
||||
return this;
|
||||
}
|
||||
|
||||
title() {
|
||||
this.properties.push(new Style("Title"));
|
||||
return this;
|
||||
}
|
||||
|
||||
center() {
|
||||
this.properties.push(new Alignment("center"));
|
||||
return this;
|
||||
}
|
||||
|
||||
left() {
|
||||
this.properties.push(new Alignment("left"));
|
||||
return this;
|
||||
}
|
||||
|
||||
right() {
|
||||
this.properties.push(new Alignment("right"));
|
||||
return this;
|
||||
}
|
||||
|
||||
justified() {
|
||||
this.properties.push(new Alignment("both"));
|
||||
return this;
|
||||
}
|
||||
|
||||
thematicBreak() {
|
||||
this.properties.push(new ThematicBreak());
|
||||
return this;
|
||||
}
|
||||
|
||||
pageBreak() {
|
||||
this.properties.push(new PageBreak());
|
||||
return this;
|
||||
}
|
||||
}
|
19
ts/docx/paragraph/page-break.ts
Normal file
19
ts/docx/paragraph/page-break.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {XmlComponent, Attributes, Run} from "../xml-components";
|
||||
|
||||
class Break implements XmlComponent {
|
||||
private br: Array<XmlComponent>;
|
||||
constructor() {
|
||||
this.br = new Array<XmlComponent>();
|
||||
this.br.push(new Attributes({
|
||||
type: "page"
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
export class PageBreak extends Run {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.r.push(new Break());
|
||||
}
|
||||
}
|
14
ts/docx/paragraph/properties.ts
Normal file
14
ts/docx/paragraph/properties.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {XmlComponent, Attributes} from "../xml-components";
|
||||
|
||||
export class ParagraphProperties implements XmlComponent {
|
||||
private pPr: Array<XmlComponent>;
|
||||
|
||||
constructor() {
|
||||
this.pPr = new Array<XmlComponent>();
|
||||
this.pPr.push(new Attributes());
|
||||
}
|
||||
|
||||
push(item: XmlComponent) {
|
||||
this.pPr.push(item);
|
||||
}
|
||||
}
|
11
ts/docx/paragraph/text-run.ts
Normal file
11
ts/docx/paragraph/text-run.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import {Run, Text} from "../xml-components";
|
||||
import {ParagraphProperties} from "./properties";
|
||||
|
||||
export class TextRun extends Run {
|
||||
|
||||
constructor(text: string) {
|
||||
super();
|
||||
this.r.push(new ParagraphProperties());
|
||||
this.r.push(new Text(text));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user