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

75 lines
1.9 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";
import { Table } from "../table";
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";
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;
}
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;
}
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
}