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

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-12 21:01:52 +01:00
// http://officeopenxml.com/WPtableGrid.php
// <xsd:complexType name="CT_TblGridCol">
// <xsd:attribute name="w" type="s:ST_TwipsMeasure"/>
// </xsd:complexType>
// <xsd:complexType name="CT_TblGridBase">
// <xsd:sequence>
// <xsd:element name="gridCol" type="CT_TblGridCol" minOccurs="0" maxOccurs="unbounded"/>
// </xsd:sequence>
// </xsd:complexType>
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
import { twipsMeasureValue } from "@util/values";
2017-03-07 19:22:10 +01:00
export class TableGrid extends XmlComponent {
2022-08-31 07:52:27 +01:00
public constructor(widths: number[] | string[]) {
super("w:tblGrid");
2019-09-13 00:51:20 +01:00
for (const width of widths) {
this.root.push(new GridCol(width));
}
2017-03-07 19:22:10 +01:00
}
}
class GridColAttributes extends XmlAttributeComponent<{ readonly w: number | string }> {
protected readonly xmlKeys = { w: "w:w" };
}
2017-03-07 19:22:10 +01:00
export class GridCol extends XmlComponent {
2022-08-31 07:52:27 +01:00
public constructor(width?: number | string) {
super("w:gridCol");
if (width !== undefined) {
this.root.push(new GridColAttributes({ w: twipsMeasureValue(width) }));
}
2017-03-07 19:22:10 +01:00
}
}