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";
|
|
|
|
|
|
|
|
import { Table } from "../table";
|
|
|
|
import { TableCellProperties } from "./table-cell-properties";
|
|
|
|
|
|
|
|
export class TableCell extends XmlComponent {
|
|
|
|
private readonly properties: TableCellProperties;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super("w:tc");
|
|
|
|
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
|
|
|
|
const retval = super.prepForXml();
|
|
|
|
if (!retval) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const content = retval["w:tc"];
|
|
|
|
if (!content[content.length - 1]["w:p"]) {
|
|
|
|
content.push(new Paragraph().prepForXml());
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public createParagraph(text?: string): Paragraph {
|
|
|
|
const para = new Paragraph(text);
|
2018-12-29 01:57:20 +00:00
|
|
|
this.addParagraph(para);
|
|
|
|
|
2018-10-23 23:44:50 +01:00
|
|
|
return para;
|
|
|
|
}
|
|
|
|
|
2018-12-29 01:57:20 +00:00
|
|
|
public get Properties(): TableCellProperties {
|
2018-10-23 23:44:50 +01:00
|
|
|
return this.properties;
|
|
|
|
}
|
|
|
|
}
|