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

60 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-06-25 12:02:53 +02:00
import { HeightRule } from "file/table/table-row/table-row-height";
2018-10-23 23:44:50 +01:00
import { XmlComponent } from "file/xml-components";
import { TableCell } from "../table-cell";
import { TableRowProperties } from "./table-row-properties";
2019-09-13 00:51:20 +01:00
export interface ITableRowOptions {
readonly cantSplit?: boolean;
readonly tableHeader?: boolean;
readonly height?: {
readonly height: number;
readonly rule: HeightRule;
};
readonly children: TableCell[];
}
2018-10-23 23:44:50 +01:00
export class TableRow extends XmlComponent {
private readonly properties: TableRowProperties;
2019-09-13 00:51:20 +01:00
constructor(private readonly options: ITableRowOptions) {
2018-10-23 23:44:50 +01:00
super("w:tr");
this.properties = new TableRowProperties();
this.root.push(this.properties);
2019-09-13 00:51:20 +01:00
for (const child of options.children) {
this.root.push(child);
2018-10-23 23:44:50 +01:00
}
2019-09-13 00:51:20 +01:00
if (options.cantSplit) {
this.properties.setCantSplit();
}
2018-10-23 23:44:50 +01:00
2019-09-13 00:51:20 +01:00
if (options.tableHeader) {
this.properties.setTableHeader();
}
2018-10-23 23:44:50 +01:00
2019-09-13 00:51:20 +01:00
if (options.height) {
this.properties.setHeight(options.height.height, options.height.rule);
}
2018-10-23 23:44:50 +01:00
}
2019-09-13 00:51:20 +01:00
public get CellCount(): number {
return this.options.children.length;
}
2019-09-13 00:51:20 +01:00
// public mergeCells(startIndex: number, endIndex: number): TableCell {
// const cellSpan = endIndex - startIndex + 1;
2019-09-13 00:51:20 +01:00
// return this.addGridSpan(startIndex, cellSpan);
// }
2019-06-25 12:02:53 +02:00
2019-09-13 00:51:20 +01:00
// private addGridSpan(index: number, cellSpan: number): TableCell {
// const remainCell = this.options.children[index];
// remainCell.addGridSpan(cellSpan);
// this.options.children.splice(index + 1, cellSpan - 1);
// this.root.splice(index + 2, cellSpan - 1);
2019-06-25 12:02:53 +02:00
2019-09-13 00:51:20 +01:00
// return remainCell;
// }
2018-10-23 23:44:50 +01:00
}