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

78 lines
2.1 KiB
TypeScript
Raw Normal View History

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);
}
2019-06-25 23:17:56 +01:00
public add(item: Paragraph | Table): TableCell {
this.root.push(item);
2018-12-29 01:57:20 +00:00
2018-10-23 23:44:50 +01:00
return this;
}
public prepForXml(): IXmlableObject | undefined {
// Cells must end with a paragraph
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
2019-06-12 01:03:36 +01:00
const para = new Paragraph({});
2019-06-25 23:17:56 +01:00
this.add(para);
2018-10-23 23:44:50 +01:00
}
return super.prepForXml();
2018-10-23 23:44:50 +01: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;
}
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
}