/
table-properties.ts
91 lines (78 loc) · 4.12 KB
/
table-properties.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// http://officeopenxml.com/WPtableProperties.php
//
// <xsd:complexType name="CT_TblPrBase">
// <xsd:sequence>
// <xsd:element name="tblStyle" type="CT_String" minOccurs="0"/>
// <xsd:element name="tblpPr" type="CT_TblPPr" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblOverlap" type="CT_TblOverlap" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="bidiVisual" type="CT_OnOff" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblStyleRowBandSize" type="CT_DecimalNumber" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblStyleColBandSize" type="CT_DecimalNumber" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblW" type="CT_TblWidth" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="jc" type="CT_JcTable" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblCellSpacing" type="CT_TblWidth" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblInd" type="CT_TblWidth" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblBorders" type="CT_TblBorders" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="shd" type="CT_Shd" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblLayout" type="CT_TblLayoutType" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblCellMar" type="CT_TblCellMar" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblLook" type="CT_TblLook" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblCaption" type="CT_String" minOccurs="0" maxOccurs="1"/>
// <xsd:element name="tblDescription" type="CT_String" minOccurs="0" maxOccurs="1"/>
// </xsd:sequence>
// </xsd:complexType>
import { IgnoreIfEmptyXmlComponent, OnOffElement, StringValueElement } from "@file/xml-components";
import { Alignment, AlignmentType } from "../../paragraph";
import { IShadingAttributesProperties, Shading } from "../../shading";
import { ITableWidthProperties, TableWidthElement } from "../table-width";
import { ITableBordersOptions, TableBorders } from "./table-borders";
import { ITableCellMarginOptions, TableCellMargin, TableCellMarginElementType } from "./table-cell-margin";
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
import { TableLayout, TableLayoutType } from "./table-layout";
export interface ITablePropertiesOptions {
readonly width?: ITableWidthProperties;
readonly indent?: ITableWidthProperties;
readonly layout?: (typeof TableLayoutType)[keyof typeof TableLayoutType];
readonly borders?: ITableBordersOptions;
readonly float?: ITableFloatOptions;
readonly shading?: IShadingAttributesProperties;
readonly style?: string;
readonly alignment?: (typeof AlignmentType)[keyof typeof AlignmentType];
readonly cellMargin?: ITableCellMarginOptions;
readonly visuallyRightToLeft?: boolean;
}
export class TableProperties extends IgnoreIfEmptyXmlComponent {
public constructor(options: ITablePropertiesOptions) {
super("w:tblPr");
if (options.style) {
this.root.push(new StringValueElement("w:tblStyle", options.style));
}
if (options.float) {
this.root.push(new TableFloatProperties(options.float));
}
if (options.visuallyRightToLeft !== undefined) {
this.root.push(new OnOffElement("w:bidiVisual", options.visuallyRightToLeft));
}
if (options.width) {
this.root.push(new TableWidthElement("w:tblW", options.width));
}
if (options.alignment) {
this.root.push(new Alignment(options.alignment));
}
if (options.indent) {
this.root.push(new TableWidthElement("w:tblInd", options.indent));
}
if (options.borders) {
this.root.push(new TableBorders(options.borders));
}
if (options.shading) {
this.root.push(new Shading(options.shading));
}
if (options.layout) {
this.root.push(new TableLayout(options.layout));
}
if (options.cellMargin) {
this.root.push(new TableCellMargin(TableCellMarginElementType.TABLE, options.cellMargin));
}
}
}