Files
docx-js/src/file/table/table-properties/table-width.ts
2021-03-04 01:42:58 +00:00

22 lines
705 B
TypeScript

// http://officeopenxml.com/WPtableWidth.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { WidthType } from "../table-cell";
interface ITableWidth {
readonly type: WidthType;
readonly w: number | string;
}
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
protected readonly xmlKeys = { type: "w:type", w: "w:w" };
}
export class PreferredTableWidth extends XmlComponent {
constructor(type: WidthType = WidthType.AUTO, w: number) {
super("w:tblW");
const width: number | string = type === WidthType.PERCENTAGE ? `${w}%` : w;
this.root.push(new TableWidthAttributes({ type: type, w: width }));
}
}