Add footnote support to API

This commit is contained in:
Dolan
2018-06-25 19:49:46 +01:00
parent 369ec9c30b
commit 99290d646e
6 changed files with 37 additions and 12 deletions

14
demo/demo16.js Normal file
View File

@ -0,0 +1,14 @@
const docx = require('../build');
var doc = new docx.Document();
var paragraph = new docx.Paragraph("Hello World").referenceFootnote(1);
doc.addParagraph(paragraph);
doc.createFootnote(new docx.Paragraph("Test"));
var exporter = new docx.LocalPacker(doc);
exporter.pack('My Document');
console.log('Document created successfully at project root!');

View File

@ -32,5 +32,6 @@ export class ContentTypes extends XmlComponent {
this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml"));
this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml", "/word/footnotes.xml"));
}
}

View File

@ -163,6 +163,10 @@ export class File {
return hyperlink;
}
public createFootnote(paragraph: Paragraph): void {
this.footNotes.createFootNote(paragraph);
}
public get Document(): Document {
return this.document;
}

View File

@ -1,6 +1,8 @@
import { XmlComponent } from "file/xml-components";
import { Paragraph } from "../paragraph";
import { FootNote } from "./footnote/footnote";
import { ContinuationSeperatorRun } from "./footnote/run/continuation-seperator-run";
import { SeperatorRun } from "./footnote/run/seperator-run";
import { FootnotesAttributes } from "./footnotes-attributes";
export class FootNotes extends XmlComponent {
@ -28,32 +30,30 @@ export class FootNotes extends XmlComponent {
}),
);
const begin = new FootNote(-1);
const begin = new FootNote(-1, "separator");
begin.addParagraph(
new Paragraph().spacing({
after: 0,
line: 240,
lineRule: "auto",
}),
}).addRun(new SeperatorRun()),
);
this.root.push(begin);
const spacing = new FootNote(0);
const spacing = new FootNote(0, "continuationSeparator");
spacing.addParagraph(
new Paragraph().spacing({
after: 0,
line: 240,
lineRule: "auto",
}),
}).addRun(new ContinuationSeperatorRun()),
);
this.root.push(spacing);
}
public createFootNote(): void {
// TODO
}
public getFootNote(): void {
// TODO
public createFootNote(paragraph: Paragraph): void {
const footnote = new FootNote(1);
footnote.addParagraph(paragraph);
this.root.push(footnote);
}
}

View File

@ -1,8 +1,8 @@
// http://officeopenxml.com/WPparagraph.php
import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
import { IMediaData } from "file/media";
import { Num } from "file/numbering/num";
import { XmlComponent } from "file/xml-components";
import { PictureRun, Run, TextRun } from "./run";
import { Alignment } from "./formatting/alignment";
import { ThematicBreak } from "./formatting/border";
@ -15,6 +15,7 @@ import { CenterTabStop, LeftTabStop, MaxRightTabStop, RightTabStop } from "./for
import { NumberProperties } from "./formatting/unordered-list";
import { Hyperlink } from "./links";
import { ParagraphProperties } from "./properties";
import { PictureRun, Run, TextRun } from "./run";
export class Paragraph extends XmlComponent {
private properties: ParagraphProperties;
@ -181,4 +182,9 @@ export class Paragraph extends XmlComponent {
this.properties.push(new KeepLines());
return this;
}
public referenceFootnote(id: number): Paragraph {
this.root.push(new FootnoteReferenceRun(id));
return this;
}
}

View File

@ -13,7 +13,7 @@ import { Underline } from "./underline";
import { XmlComponent } from "file/xml-components";
export class Run extends XmlComponent {
private properties: RunProperties;
protected properties: RunProperties;
constructor() {
super("w:r");