Allows user to specify style id for Tables
Allows user to specify the style Id which will be added in the form of: <w:tblStyle w:val="TableGrid"/> As specified in table Structure in http://officeopenxml.com/WPtable.php
This commit is contained in:
@ -6,6 +6,7 @@ import { TableBorders } from "./table-borders";
|
|||||||
import { TableCellMargin } from "./table-cell-margin";
|
import { TableCellMargin } from "./table-cell-margin";
|
||||||
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
|
import { ITableFloatOptions, TableFloatProperties } from "./table-float-properties";
|
||||||
import { TableLayout, TableLayoutType } from "./table-layout";
|
import { TableLayout, TableLayoutType } from "./table-layout";
|
||||||
|
import { TableStyle } from "./table-style";
|
||||||
import { PreferredTableWidth } from "./table-width";
|
import { PreferredTableWidth } from "./table-width";
|
||||||
|
|
||||||
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
@ -46,4 +47,9 @@ export class TableProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setStyle(styleId: string): TableProperties {
|
||||||
|
this.root.push(new TableStyle(styleId));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
15
src/file/table/table-properties/table-style.ts
Normal file
15
src/file/table/table-properties/table-style.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Attributes, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
export class TableStyle extends XmlComponent {
|
||||||
|
public readonly styleId: string;
|
||||||
|
|
||||||
|
constructor(styleId: string) {
|
||||||
|
super("w:tblStyle");
|
||||||
|
this.styleId = styleId;
|
||||||
|
this.root.push(
|
||||||
|
new Attributes({
|
||||||
|
val: styleId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -32,6 +32,7 @@ export interface ITableOptions {
|
|||||||
};
|
};
|
||||||
readonly float?: ITableFloatOptions;
|
readonly float?: ITableFloatOptions;
|
||||||
readonly layout?: TableLayoutType;
|
readonly layout?: TableLayoutType;
|
||||||
|
readonly style?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Table extends XmlComponent {
|
export class Table extends XmlComponent {
|
||||||
@ -44,6 +45,7 @@ export class Table extends XmlComponent {
|
|||||||
margins: { marginUnitType, top, bottom, right, left } = { marginUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
|
margins: { marginUnitType, top, bottom, right, left } = { marginUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
|
||||||
float,
|
float,
|
||||||
layout,
|
layout,
|
||||||
|
style,
|
||||||
}: ITableOptions) {
|
}: ITableOptions) {
|
||||||
super("w:tbl");
|
super("w:tbl");
|
||||||
this.properties = new TableProperties();
|
this.properties = new TableProperties();
|
||||||
@ -96,5 +98,9 @@ export class Table extends XmlComponent {
|
|||||||
if (layout) {
|
if (layout) {
|
||||||
this.properties.setLayout(layout);
|
this.properties.setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (style) {
|
||||||
|
this.properties.setStyle(style);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user