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

69 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-11-24 03:22:50 +00:00
// http://officeopenxml.com/WPtableProperties.php
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
2018-10-23 23:44:50 +01:00
2019-11-24 01:22:17 +00:00
import { Alignment, AlignmentType } from "../../paragraph";
2019-03-21 01:06:07 +00:00
import { ITableShadingAttributesProperties, TableShading } from "../shading";
2018-10-23 23:44:50 +01:00
import { WidthType } from "../table-cell";
2019-11-18 01:04:31 +00:00
import { ITableBordersOptions, TableBorders } from "./table-borders";
2021-03-04 01:42:58 +00:00
import { ITableCellMarginOptions, TableCellMargin } from "./table-cell-margin";
2018-10-23 23:44:50 +01:00
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
import { TableLayout, TableLayoutType } from "./table-layout";
import { TableStyle } from "./table-style";
2018-10-23 23:44:50 +01:00
import { PreferredTableWidth } from "./table-width";
import { VisuallyRightToLeft } from "./visually-right-to-left";
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
export interface ITablePropertiesOptions {
readonly width?: {
readonly size: number;
readonly type?: WidthType;
};
readonly layout?: TableLayoutType;
readonly borders?: ITableBordersOptions;
readonly float?: ITableFloatOptions;
readonly shading?: ITableShadingAttributesProperties;
readonly style?: string;
2021-03-04 01:42:58 +00:00
readonly alignment?: AlignmentType;
readonly cellMargin?: ITableCellMarginOptions;
readonly visuallyRightToLeft?: boolean;
2021-03-04 01:42:58 +00:00
}
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
export class TableProperties extends IgnoreIfEmptyXmlComponent {
constructor(options: ITablePropertiesOptions) {
2018-10-23 23:44:50 +01:00
super("w:tblPr");
2021-03-04 01:42:58 +00:00
this.root.push(new TableCellMargin(options.cellMargin || {}));
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
if (options.borders) {
this.root.push(new TableBorders(options.borders));
}
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
if (options.width) {
this.root.push(new PreferredTableWidth(options.width.type, options.width.size));
}
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
if (options.float) {
this.root.push(new TableFloatProperties(options.float));
}
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
if (options.layout) {
this.root.push(new TableLayout(options.layout));
}
2018-10-23 23:44:50 +01:00
2021-03-04 01:42:58 +00:00
if (options.alignment) {
this.root.push(new Alignment(options.alignment));
}
2019-03-21 01:06:07 +00:00
2021-03-04 01:42:58 +00:00
if (options.shading) {
this.root.push(new TableShading(options.shading));
}
2019-03-21 01:06:07 +00:00
if (options.visuallyRightToLeft) {
this.root.push(new VisuallyRightToLeft());
}
if (options.style) {
this.root.push(new TableStyle(options.style));
}
}
2018-10-23 23:44:50 +01:00
}