2018-02-03 20:56:20 +00:00
|
|
|
import { ContentTypes } from "./content-types/content-types";
|
2017-12-15 01:16:04 +00:00
|
|
|
import { Document } from "./document";
|
2018-01-24 13:09:34 +00:00
|
|
|
import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties";
|
2018-01-31 00:31:54 +00:00
|
|
|
import { FooterWrapper } from "./footer-wrapper";
|
|
|
|
import { HeaderWrapper } from "./header-wrapper";
|
2017-12-20 00:06:08 +00:00
|
|
|
import { Media } from "./media";
|
2017-12-20 00:01:23 +00:00
|
|
|
import { Numbering } from "./numbering";
|
|
|
|
import { Paragraph } from "./paragraph";
|
2017-12-20 00:58:24 +00:00
|
|
|
import { IPropertiesOptions, Properties } from "./properties";
|
2018-01-29 01:54:10 +00:00
|
|
|
import { Relationships } from "./relationships";
|
2017-12-20 00:52:41 +00:00
|
|
|
import { Styles } from "./styles";
|
|
|
|
import { DefaultStylesFactory } from "./styles/factory";
|
2017-12-20 00:01:23 +00:00
|
|
|
import { Table } from "./table";
|
2017-12-15 01:16:04 +00:00
|
|
|
|
|
|
|
export class File {
|
2018-01-29 01:54:10 +00:00
|
|
|
private readonly document: Document;
|
|
|
|
private readonly styles: Styles;
|
|
|
|
private readonly properties: Properties;
|
|
|
|
private readonly numbering: Numbering;
|
|
|
|
private readonly media: Media;
|
2018-02-04 00:58:34 +00:00
|
|
|
private readonly docRelationships: Relationships;
|
|
|
|
private readonly fileRelationships: Relationships;
|
2018-01-31 00:31:54 +00:00
|
|
|
private readonly headerWrapper: HeaderWrapper;
|
|
|
|
private readonly footerWrapper: FooterWrapper;
|
2018-02-03 20:56:20 +00:00
|
|
|
private readonly contentTypes: ContentTypes;
|
2017-12-15 01:16:04 +00:00
|
|
|
|
2018-01-24 13:09:34 +00:00
|
|
|
constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) {
|
|
|
|
this.document = new Document(sectionPropertiesOptions);
|
2017-12-15 02:15:44 +00:00
|
|
|
const stylesFactory = new DefaultStylesFactory();
|
|
|
|
this.styles = stylesFactory.newInstance();
|
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
options = {
|
|
|
|
creator: "Un-named",
|
|
|
|
revision: "1",
|
|
|
|
lastModifiedBy: "Un-named",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.properties = new Properties(options);
|
2017-12-15 01:16:04 +00:00
|
|
|
this.numbering = new Numbering();
|
2018-02-04 00:58:34 +00:00
|
|
|
this.docRelationships = new Relationships();
|
|
|
|
this.docRelationships.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles", "styles.xml");
|
|
|
|
this.docRelationships.createRelationship(2, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering", "numbering.xml");
|
|
|
|
this.docRelationships.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", "header1.xml");
|
|
|
|
this.docRelationships.createRelationship(4, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", "footer1.xml");
|
2018-01-29 01:54:10 +00:00
|
|
|
this.media = new Media();
|
2018-01-31 00:31:54 +00:00
|
|
|
this.headerWrapper = new HeaderWrapper(this.media);
|
|
|
|
this.footerWrapper = new FooterWrapper(this.media);
|
2018-02-03 20:56:20 +00:00
|
|
|
this.contentTypes = new ContentTypes();
|
2018-02-04 00:58:34 +00:00
|
|
|
this.fileRelationships = new Relationships();
|
|
|
|
this.fileRelationships.createRelationship(1, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", "word/document.xml");
|
|
|
|
this.fileRelationships.createRelationship(2, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml");
|
|
|
|
this.fileRelationships.createRelationship(3, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml");
|
2017-12-15 01:16:04 +00:00
|
|
|
}
|
2017-12-15 02:15:44 +00:00
|
|
|
|
|
|
|
public addParagraph(paragraph: Paragraph): void {
|
|
|
|
this.document.addParagraph(paragraph);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createParagraph(text?: string): Paragraph {
|
2018-01-29 02:56:35 +00:00
|
|
|
return this.document.createParagraph(text);
|
2017-12-15 02:15:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public addTable(table: Table): void {
|
|
|
|
return this.document.addTable(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
public createTable(rows: number, cols: number): Table {
|
|
|
|
return this.document.createTable(rows, cols);
|
|
|
|
}
|
|
|
|
|
2018-01-11 01:47:09 +00:00
|
|
|
public createImage(image: string): void {
|
2018-02-04 00:58:34 +00:00
|
|
|
const mediaData = this.media.addMedia(image, this.docRelationships.RelationshipCount);
|
|
|
|
this.docRelationships.createRelationship(
|
2018-01-23 01:33:12 +00:00
|
|
|
mediaData.referenceId,
|
|
|
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
|
|
`media/${mediaData.fileName}`,
|
|
|
|
);
|
2018-01-11 01:47:09 +00:00
|
|
|
this.document.createDrawing(mediaData);
|
|
|
|
}
|
|
|
|
|
2017-12-15 02:15:44 +00:00
|
|
|
public get Document(): Document {
|
|
|
|
return this.document;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Styles(): Styles {
|
|
|
|
return this.styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Properties(): Properties {
|
|
|
|
return this.properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Numbering(): Numbering {
|
|
|
|
return this.numbering;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get Media(): Media {
|
|
|
|
return this.media;
|
|
|
|
}
|
2018-01-10 00:29:17 +00:00
|
|
|
|
2018-02-04 00:58:34 +00:00
|
|
|
public get DocumentRelationships(): Relationships {
|
|
|
|
return this.docRelationships;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get FileRelationships(): Relationships {
|
|
|
|
return this.fileRelationships;
|
2018-01-10 00:29:17 +00:00
|
|
|
}
|
2018-01-29 01:54:10 +00:00
|
|
|
|
2018-01-31 00:31:54 +00:00
|
|
|
public get Header(): HeaderWrapper {
|
|
|
|
return this.headerWrapper;
|
2018-01-29 01:54:10 +00:00
|
|
|
}
|
2018-01-29 21:53:22 +00:00
|
|
|
|
2018-01-31 00:31:54 +00:00
|
|
|
public get Footer(): FooterWrapper {
|
|
|
|
return this.footerWrapper;
|
2018-01-29 21:53:22 +00:00
|
|
|
}
|
2018-02-03 20:56:20 +00:00
|
|
|
|
|
|
|
public get ContentTypes(): ContentTypes {
|
|
|
|
return this.contentTypes;
|
|
|
|
}
|
2017-12-15 01:16:04 +00:00
|
|
|
}
|