This commit is contained in:
amitm02
2018-09-04 17:16:31 +03:00
parent 010fde6258
commit 03c4190c2c
20 changed files with 363 additions and 117 deletions

View File

@ -1,7 +1,7 @@
import { expect } from "chai";
import { Formatter } from "../../../../export/formatter";
import { FooterReferenceType, PageBorderOffsetFrom, PageNumberFormat } from "./";
import { PageBorderOffsetFrom, PageNumberFormat, FooterReferenceType, HeaderReferenceType } from "./";
import { SectionProperties } from "./section-properties";
describe("SectionProperties", () => {
@ -19,9 +19,8 @@ describe("SectionProperties", () => {
gutter: 0,
space: 708,
linePitch: 360,
headerId: 100,
footerId: 200,
footerType: FooterReferenceType.EVEN,
headers: [{headerId: 100, headerType: HeaderReferenceType.DEFAULT}],
footers: [{footerId: 200, footerType: FooterReferenceType.EVEN}],
pageNumberStart: 10,
pageNumberFormatType: PageNumberFormat.CARDINAL_TEXT,
});

View File

@ -1,24 +1,27 @@
// http://officeopenxml.com/WPsection.php
import { XmlComponent } from "file/xml-components";
import { FooterReferenceType, IPageBordersOptions, IPageNumberTypeAttributes, PageBorders, PageNumberFormat, PageNumberType } from "./";
import { IPageBordersOptions, IPageNumberTypeAttributes, PageBorders, PageNumberFormat, PageNumberType } from "./";
import { Columns } from "./columns/columns";
import { IColumnsAttributes } from "./columns/columns-attributes";
import { DocumentGrid } from "./doc-grid/doc-grid";
import { IDocGridAttributesProperties } from "./doc-grid/doc-grid-attributes";
import { FooterReference, IFooterOptions } from "./footer-reference/footer-reference";
import { HeaderReference, IHeaderOptions } from "./header-reference/header-reference";
import { HeaderReferenceType } from "./header-reference/header-reference-attributes";
import { PageMargin } from "./page-margin/page-margin";
import { IPageMarginAttributes } from "./page-margin/page-margin-attributes";
import { PageSize } from "./page-size/page-size";
import { IPageSizeAttributes, PageOrientation } from "./page-size/page-size-attributes";
import { TitlePage } from "./title-page/title-page";
type IHeadersOptions = {headers? : IHeaderOptions[]}
type IFootersOptions = {footers? : IFooterOptions[]}
export type SectionPropertiesOptions = IPageSizeAttributes &
IPageMarginAttributes &
IColumnsAttributes &
IDocGridAttributesProperties &
IHeaderOptions &
IFooterOptions &
IHeadersOptions &
IFootersOptions &
IPageNumberTypeAttributes &
IPageBordersOptions;
@ -41,10 +44,8 @@ export class SectionProperties extends XmlComponent {
space: 708,
linePitch: 360,
orientation: PageOrientation.PORTRAIT,
headerType: HeaderReferenceType.DEFAULT,
headerId: 0,
footerType: FooterReferenceType.DEFAULT,
footerId: 0,
headers: [],
footers: [],
pageNumberStart: undefined,
pageNumberFormatType: PageNumberFormat.DECIMAL,
pageBorders: undefined,
@ -52,6 +53,7 @@ export class SectionProperties extends XmlComponent {
pageBorderRight: undefined,
pageBorderBottom: undefined,
pageBorderLeft: undefined,
titlePage : true
};
const mergedOptions = {
@ -59,6 +61,7 @@ export class SectionProperties extends XmlComponent {
...options,
};
this.root.push(new PageSize(mergedOptions.width, mergedOptions.height, mergedOptions.orientation));
this.root.push(
new PageMargin(
@ -74,19 +77,24 @@ export class SectionProperties extends XmlComponent {
this.root.push(new Columns(mergedOptions.space));
this.root.push(new DocumentGrid(mergedOptions.linePitch));
this.root.push(
new HeaderReference({
headerType: mergedOptions.headerType,
headerId: mergedOptions.headerId,
}),
);
this.root.push(
new FooterReference({
footerType: mergedOptions.footerType,
footerId: mergedOptions.footerId,
}),
);
for (let header of mergedOptions.headers) {
this.root.push(
new HeaderReference({
headerType: header.headerType,
headerId: header.headerId,
}),
);
}
for (let footer of mergedOptions.footers) {
this.root.push(
new FooterReference({
footerType: footer.footerType,
footerId: footer.footerId,
}),
);
}
this.root.push(new PageNumberType(mergedOptions.pageNumberStart, mergedOptions.pageNumberFormatType));
if (
@ -107,6 +115,10 @@ export class SectionProperties extends XmlComponent {
);
}
if (mergedOptions.titlePage) {
this.root.push(new TitlePage());
}
this.options = mergedOptions;
}