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

22 lines
705 B
TypeScript
Raw Normal View History

2019-03-04 22:50:04 +00:00
// http://officeopenxml.com/WPtableWidth.php
2018-10-23 23:44:50 +01:00
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { WidthType } from "../table-cell";
interface ITableWidth {
readonly type: WidthType;
readonly w: number | string;
2018-10-23 23:44:50 +01:00
}
class TableWidthAttributes extends XmlAttributeComponent<ITableWidth> {
protected readonly xmlKeys = { type: "w:type", w: "w:w" };
2018-10-23 23:44:50 +01:00
}
export class PreferredTableWidth extends XmlComponent {
2021-03-04 01:42:58 +00:00
constructor(type: WidthType = WidthType.AUTO, w: number) {
2018-10-23 23:44:50 +01:00
super("w:tblW");
const width: number | string = type === WidthType.PERCENTAGE ? `${w}%` : w;
this.root.push(new TableWidthAttributes({ type: type, w: width }));
2018-10-23 23:44:50 +01:00
}
}