Create section properties section

This commit is contained in:
Dolan
2018-01-24 00:01:38 +00:00
parent ff5d02c964
commit df197f73ea
17 changed files with 169 additions and 88 deletions

View File

@ -0,0 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IColumnsAttributes {
space?: number;
}
export class ColumnsAttributes extends XmlAttributeComponent<IColumnsAttributes> {
protected xmlKeys = {
space: "w:space",
};
}

View File

@ -0,0 +1,13 @@
import { XmlComponent } from "file/xml-components";
import { ColumnsAttributes } from "./columns-attributes";
export class Columns extends XmlComponent {
constructor(space: number) {
super("w:cols");
this.root.push(
new ColumnsAttributes({
space: space,
}),
);
}
}

View File

@ -0,0 +1,11 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IDocGridAttributesProperties {
linePitch?: number;
}
export class DocGridAttributes extends XmlAttributeComponent<IDocGridAttributesProperties> {
protected xmlKeys = {
linePitch: "w:linePitch",
};
}

View File

@ -0,0 +1,13 @@
import { XmlComponent } from "file/xml-components";
import { DocGridAttributes } from "./doc-grid-attributes";
export class DocumentGrid extends XmlComponent {
constructor(linePitch: number) {
super("w:docGrid");
this.root.push(
new DocGridAttributes({
linePitch: linePitch,
}),
);
}
}

View File

@ -0,0 +1,23 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IPageMarginAttributes {
top: number;
right: number;
bottom: number;
left: number;
header: number;
footer: number;
gutter: number;
}
export class PageMarginAttributes extends XmlAttributeComponent<IPageMarginAttributes> {
protected xmlKeys = {
top: "w:top",
right: "w:right",
bottom: "w:bottom",
left: "w:left",
header: "w:header",
footer: "w:footer",
gutter: "w:gutter",
};
}

View File

@ -0,0 +1,19 @@
import { XmlComponent } from "file/xml-components";
import { PageMarginAttributes } from "./page-margin-attributes";
export class PageMargin extends XmlComponent {
constructor(top: number, right: number, bottom: number, left: number, header: number, footer: number, gutter: number) {
super("w:pgMar");
this.root.push(
new PageMarginAttributes({
top: top,
right: right,
bottom: bottom,
left: left,
header: header,
footer: footer,
gutter: gutter,
}),
);
}
}

View File

@ -0,0 +1,13 @@
import { XmlAttributeComponent } from "file/xml-components";
export interface IPageSizeAttributes {
width: number;
height: number;
}
export class PageSizeAttributes extends XmlAttributeComponent<IPageSizeAttributes> {
protected xmlKeys = {
width: "w:w",
height: "w:h",
};
}

View File

@ -0,0 +1,15 @@
import { XmlComponent } from "file/xml-components";
import { PageSizeAttributes } from "./page-size-attributes";
export class PageSize extends XmlComponent {
constructor(width: number, height: number) {
super("w:pgSz");
this.root.push(
new PageSizeAttributes({
width: width,
height: height,
}),
);
}
}

View File

@ -0,0 +1,23 @@
// http://officeopenxml.com/WPsection.php
import { IColumnsAttributes } from "file/document/body/section-properties/columns/columns-attributes";
import { IPageMarginAttributes } from "file/document/body/section-properties/page-margin/page-margin-attributes";
import { IPageSizeAttributes } from "file/document/body/section-properties/page-size/page-size-attributes";
import { XmlComponent } from "file/xml-components";
import { Columns } from "./columns/columns";
import { DocumentGrid } from "./doc-grid/doc-grid";
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
import { PageMargin } from "./page-margin/page-margin";
import { PageSize } from "./page-size/page-size";
export type SectionPropertiesOptions = IPageSizeAttributes & IPageMarginAttributes & IColumnsAttributes & IDocGridAttributesProperties;
export class SectionProperties extends XmlComponent {
constructor(options: SectionPropertiesOptions) {
super("w:sectPr");
this.root.push(new PageSize(11906, 16838));
this.root.push(new PageMargin(1440, 1440, 1440, 1440, 708, 708, 0));
this.root.push(new Columns(708));
this.root.push(new DocumentGrid(308));
}
}