Files
docx-js/src/file/table/properties.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
2017-03-07 19:22:10 +01:00
export type WidthTypes = "dxa" | "pct" | "nil" | "auto";
2017-03-07 19:22:10 +01:00
export class TableProperties extends XmlComponent {
2017-03-07 19:22:10 +01:00
constructor() {
super("w:tblPr");
2017-03-07 19:22:10 +01:00
}
public setWidth(type: WidthTypes, w: number | string): TableProperties {
this.root.push(new PreferredTableWidth(type, w));
return this;
2017-03-07 19:22:10 +01:00
}
public fixedWidthLayout(): TableProperties {
this.root.push(new TableLayout("fixed"));
return this;
}
2017-03-07 19:22:10 +01:00
}
interface ITableWidth {
type: WidthTypes;
w: number | string;
}
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
2018-01-23 01:33:12 +00:00
protected xmlKeys = { type: "w:type", w: "w:w" };
}
2017-03-07 19:22:10 +01:00
class PreferredTableWidth extends XmlComponent {
constructor(type: WidthTypes, w: number | string) {
super("w:tblW");
2018-01-23 01:33:12 +00:00
this.root.push(new TableWidthAttributes({ type, w }));
2017-03-07 19:22:10 +01:00
}
}
type TableLayoutOptions = "autofit" | "fixed";
2018-01-23 01:33:12 +00:00
class TableLayoutAttributes extends XmlAttributeComponent<{ type: TableLayoutOptions }> {
protected xmlKeys = { type: "w:type" };
}
class TableLayout extends XmlComponent {
constructor(type: TableLayoutOptions) {
super("w:tblLayout");
2018-01-23 01:33:12 +00:00
this.root.push(new TableLayoutAttributes({ type }));
}
}