/
table-cell.ts
30 lines (24 loc) · 1017 Bytes
/
table-cell.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// http://officeopenxml.com/WPtableGrid.php
import { Paragraph } from "@file/paragraph";
import { IContext, IXmlableObject, XmlComponent } from "@file/xml-components";
import { Table } from "../table";
import { ITableCellPropertiesOptions, TableCellProperties } from "./table-cell-properties";
export interface ITableCellOptions extends ITableCellPropertiesOptions {
readonly children: readonly (Paragraph | Table)[];
}
export class TableCell extends XmlComponent {
public constructor(public readonly options: ITableCellOptions) {
super("w:tc");
this.root.push(new TableCellProperties(options));
for (const child of options.children) {
this.root.push(child);
}
}
public prepForXml(context: IContext): IXmlableObject | undefined {
// Cells must end with a paragraph
if (!(this.root[this.root.length - 1] instanceof Paragraph)) {
this.root.push(new Paragraph({}));
}
return super.prepForXml(context);
}
}