Merge pull request #179 from dolanmiu/feat/import-dotx

Feat/import dotx
This commit is contained in:
Dolan
2018-10-23 00:47:18 +01:00
committed by GitHub
40 changed files with 871 additions and 275 deletions

View File

@ -21,8 +21,10 @@ export class TableCellMargin extends XmlComponent {
super("w:tblCellMar");
}
public prepForXml(): IXmlableObject {
return this.root.length > 0 ? super.prepForXml() : "";
public prepForXml(): IXmlableObject | undefined {
if (this.root.length > 0) {
return super.prepForXml();
}
}
public addTopMargin(value: number, type: WidthType = WidthType.DXA): void {

View File

@ -8,8 +8,7 @@ describe("TableCellBorders", () => {
describe("#prepForXml", () => {
it("should not add empty borders element if there are no borders defined", () => {
const tb = new TableCellBorders();
const tree = new Formatter().format(tb);
expect(tree).to.deep.equal("");
expect(() => new Formatter().format(tb)).to.throw();
});
});

View File

@ -29,8 +29,10 @@ export class TableCellBorders extends XmlComponent {
super("w:tcBorders");
}
public prepForXml(): IXmlableObject {
return this.root.length > 0 ? super.prepForXml() : "";
public prepForXml(): IXmlableObject | undefined {
if (this.root.length > 0) {
return super.prepForXml();
}
}
public addTopBorder(style: BorderStyle, size: number, color: string): TableCellBorders {

View File

@ -145,9 +145,13 @@ export class TableCell extends XmlComponent {
return this;
}
public prepForXml(): IXmlableObject {
public prepForXml(): IXmlableObject | undefined {
// Cells must end with a paragraph
const retval = super.prepForXml();
if (!retval) {
return undefined;
}
const content = retval["w:tc"];
if (!content[content.length - 1]["w:p"]) {
content.push(new Paragraph().prepForXml());