added fixedWidthLayout option and method

This commit is contained in:
felipe
2017-03-11 09:59:29 +01:00
parent 210b97d00b
commit c10b576a3a
4 changed files with 48 additions and 0 deletions

View File

@ -55,6 +55,11 @@ export class Table extends XmlComponent {
this.properties.setWidth(type, width); this.properties.setWidth(type, width);
return this; return this;
} }
public fixedWidthLayout(): Table {
this.properties.fixedWidthLayout();
return this;
}
} }
class TableRow extends XmlComponent { class TableRow extends XmlComponent {

View File

@ -11,6 +11,11 @@ export class TableProperties extends XmlComponent {
this.root.push(new PreferredTableWidth(type, w)); this.root.push(new PreferredTableWidth(type, w));
return this; return this;
} }
public fixedWidthLayout(): TableProperties {
this.root.push(new TableLayout("fixed"));
return this;
}
} }
interface ITableWidth { interface ITableWidth {
@ -28,3 +33,16 @@ class PreferredTableWidth extends XmlComponent {
this.root.push(new TableWidthAttributes({type, w})); this.root.push(new TableWidthAttributes({type, w}));
} }
} }
type tableLayout = "autofit" | "fixed";
class TableLayoutAttributes extends XmlAttributeComponent<{type: tableLayout}> {
protected xmlKeys = {type: "w:type"};
}
class TableLayout extends XmlComponent {
constructor(type: tableLayout) {
super("w:tblLayout");
this.root.push(new TableLayoutAttributes({type}));
}
}

View File

@ -22,4 +22,16 @@ describe("TableProperties", () => {
}); });
}); });
}); });
describe("#fixedWidthLayout", () => {
it("sets the table to fixed width layout", () => {
const tp = new TableProperties().fixedWidthLayout();
const tree = new Formatter().format(tp);
expect(tree).to.deep.equal({
"w:tblPr": [
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
],
});
});
});
}); });

View File

@ -93,4 +93,17 @@ describe("Table", () => {
}); });
}); });
}); });
describe("#fixedWidthLayout", () => {
it("sets the table to fixed width layout", () => {
const table = new Table(2, 2).fixedWidthLayout();
const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array").with.has.length.at.least(1);
expect(tree["w:tbl"][0]).to.deep.equal({
"w:tblPr": [
{"w:tblLayout": [{_attr: {"w:type": "fixed"}}]},
],
});
});
});
}); });