2018-10-23 23:44:50 +01:00
|
|
|
// http://officeopenxml.com/WPtableGrid.php
|
|
|
|
import { Paragraph } from "file/paragraph";
|
|
|
|
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
|
|
|
|
2019-03-21 01:06:07 +00:00
|
|
|
import { ITableShadingAttributesProperties } from "../shading";
|
2018-10-23 23:44:50 +01:00
|
|
|
import { Table } from "../table";
|
2019-04-18 13:55:18 +10:00
|
|
|
import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins";
|
2019-03-04 22:50:04 +00:00
|
|
|
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
2018-10-23 23:44:50 +01:00
|
|
|
import { TableCellProperties } from "./table-cell-properties";
|
|
|
|
|
2019-06-25 01:21:28 +01:00
|
|
|
export interface ITableCellOptions {
|
|
|
|
readonly shading?: ITableShadingAttributesProperties;
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:44:50 +01:00
|
|
|
export class TableCell extends XmlComponent {
|
|
|
|
private readonly properties: TableCellProperties;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super("w:tc");
|
2019-03-18 23:50:21 +00:00
|
|
|
|
2018-10-23 23:44:50 +01:00
|
|
|
this.properties = new TableCellProperties();
|
|
|
|
this.root.push(this.properties);
|
|
|
|
}
|
|
|
|
|
2018-12-29 01:57:20 +00:00
|
|
|
public addParagraph(content: Paragraph): TableCell {
|
|
|
|
this.root.push(content);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addTable(content: Table): TableCell {
|
2018-10-23 23:44:50 +01:00
|
|
|
this.root.push(content);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public prepForXml(): IXmlableObject | undefined {
|
|
|
|
// Cells must end with a paragraph
|
2019-04-09 05:27:18 -04:00
|
|
|
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
|
2019-06-12 01:03:36 +01:00
|
|
|
const para = new Paragraph({});
|
|
|
|
this.addParagraph(para);
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|
2019-04-09 05:27:18 -04:00
|
|
|
return super.prepForXml();
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 01:55:15 +00:00
|
|
|
public setVerticalAlign(type: VerticalAlign): TableCell {
|
|
|
|
this.properties.setVerticalAlign(type);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public addGridSpan(cellSpan: number): TableCell {
|
|
|
|
this.properties.addGridSpan(cellSpan);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-03-04 22:50:04 +00:00
|
|
|
public addVerticalMerge(type: VMergeType): TableCell {
|
|
|
|
this.properties.addVerticalMerge(type);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-04-18 13:55:18 +10:00
|
|
|
public setMargins(margins: ITableCellMarginOptions): TableCell {
|
|
|
|
this.properties.addMargins(margins);
|
2019-03-18 23:50:21 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-03-21 01:06:07 +00:00
|
|
|
public setShading(attrs: ITableShadingAttributesProperties): TableCell {
|
|
|
|
this.properties.setShading(attrs);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-12-31 01:55:15 +00:00
|
|
|
public get Borders(): TableCellBorders {
|
|
|
|
return this.properties.Borders;
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|
2019-03-05 11:38:21 +01:00
|
|
|
|
|
|
|
public get Properties(): TableCellProperties {
|
|
|
|
return this.properties;
|
|
|
|
}
|
2018-10-23 23:44:50 +01:00
|
|
|
}
|