trying to get numbering to work

This commit is contained in:
Dolan Miu
2016-05-23 22:23:05 +01:00
parent 1f28fca5bf
commit 23d08df9a2
11 changed files with 31 additions and 10 deletions

View File

@ -6,4 +6,5 @@
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" /> <Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" /> <Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" /> <Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" />
</Types> </Types>

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" /> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml" />
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering" Target="numbering.xml" />
</Relationships> </Relationships>

View File

@ -1,4 +1,5 @@
import {BaseXmlComponent} from "./base"; import {BaseXmlComponent} from "./base";
import * as _ from "lodash";
export abstract class XmlAttributeComponent extends BaseXmlComponent { export abstract class XmlAttributeComponent extends BaseXmlComponent {
protected root: Object; protected root: Object;

View File

@ -32,7 +32,7 @@ export class Formatter {
} }
}); });
return newJson return newJson;
} }
private jsonify(obj: Object): Object { private jsonify(obj: Object): Object {

View File

@ -4,11 +4,12 @@ import * as express from "express";
import {Document} from "../../docx/document"; import {Document} from "../../docx/document";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
import {DefaultStylesFactory} from "../../styles/factory" import {DefaultStylesFactory} from "../../styles/factory"
import {Numbering} from "../../numbering";
export class ExpressPacker extends Packer { export class ExpressPacker extends Packer {
private res: express.Response; private res: express.Response;
constructor(document: Document, res: express.Response, styles?: any, properties?: Properties) { constructor(document: Document, res: express.Response, styles?: any, properties?: Properties, numbering?: Numbering) {
if (!styles) { if (!styles) {
var stylesFactory = new DefaultStylesFactory(); var stylesFactory = new DefaultStylesFactory();
styles = stylesFactory.newInstance() styles = stylesFactory.newInstance()
@ -22,7 +23,11 @@ export class ExpressPacker extends Packer {
}); });
} }
super(document, styles, properties); if (!numbering) {
numbering = new Numbering();
}
super(document, styles, properties, numbering);
this.res = res; this.res = res;
this.res.on('close', () => { this.res.on('close', () => {

View File

@ -2,12 +2,18 @@ import {Packer} from "./packer";
import * as fs from 'fs'; import * as fs from 'fs';
import {Document} from "../../docx/document"; import {Document} from "../../docx/document";
import {Properties} from "../../properties"; import {Properties} from "../../properties";
import {Numbering} from "../../numbering";
export class LocalPacker extends Packer { export class LocalPacker extends Packer {
private stream: fs.WriteStream private stream: fs.WriteStream
constructor(document: Document, style: any, properties: Properties, path: string) { constructor(document: Document, style: any, properties: Properties, path: string, numbering?: Numbering) {
super(document, style, properties);
if (!numbering) {
numbering = new Numbering();
}
super(document, style, properties, numbering);
this.stream = fs.createWriteStream(path); this.stream = fs.createWriteStream(path);
} }

View File

@ -53,6 +53,8 @@ export abstract class Packer {
var xmlStyles = xml(this.formatter.format(this.style)); var xmlStyles = xml(this.formatter.format(this.style));
var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } }); var xmlProperties = xml(this.formatter.format(this.properties), { declaration: { standalone: 'yes', encoding: 'UTF-8' } });
var xmlNumbering = xml(this.formatter.format(this.numbering)); var xmlNumbering = xml(this.formatter.format(this.numbering));
console.log(xmlNumbering);
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: 'word/document.xml' name: 'word/document.xml'
}); });

View File

@ -5,6 +5,7 @@ import {Level} from "./level";
import {Indent} from "./indent"; import {Indent} from "./indent";
import {RunFonts} from "./run-fonts"; import {RunFonts} from "./run-fonts";
import {Num} from "./num"; import {Num} from "./num";
import * as _ from "lodash";
export class Numbering extends MultiPropertyXmlComponent { export class Numbering extends MultiPropertyXmlComponent {
@ -80,4 +81,10 @@ export class Numbering extends MultiPropertyXmlComponent {
this.root.push(abstractNumbering); this.root.push(abstractNumbering);
this.root.push(new Num(1, 0)); this.root.push(new Num(1, 0));
} }
clearVariables() {
_.forEach(this.root, element => {
element.clearVariables();
});
}
} }

View File

@ -50,7 +50,7 @@ export class DefaultStylesFactory {
//listParagraph.addParagraphProperty(); //listParagraph.addParagraphProperty();
styles.push(listParagraph); styles.push(listParagraph);
console.log(JSON.stringify(styles, null, " ")); //console.log(JSON.stringify(styles, null, " "));
return styles; return styles;
} }
} }

View File

@ -29,8 +29,6 @@ export class Styles extends XmlComponent {
} }
clearVariables() { clearVariables() {
console.log(this);
console.log(this.root);
this.root.forEach(element => { this.root.forEach(element => {
element.clearVariables(); element.clearVariables();
}) })