Clean up table with improved demo

This commit is contained in:
Dolan Miu
2021-03-05 03:03:02 +00:00
parent 9557015c6c
commit e5da573041
4 changed files with 114 additions and 36 deletions

View File

@ -48,69 +48,59 @@ export interface ITableCellOptions {
}
export class TableCell extends XmlComponent {
private readonly properties: TableCellProperties;
constructor(readonly options: ITableCellOptions) {
super("w:tc");
this.properties = new TableCellProperties();
this.root.push(this.properties);
const properties = new TableCellProperties();
this.root.push(properties);
for (const child of options.children) {
this.root.push(child);
}
if (options.verticalAlign) {
this.properties.setVerticalAlign(options.verticalAlign);
properties.setVerticalAlign(options.verticalAlign);
}
if (options.textDirection) {
this.properties.setTextDirection(options.textDirection);
properties.setTextDirection(options.textDirection);
}
if (options.verticalMerge) {
this.properties.addVerticalMerge(options.verticalMerge);
properties.addVerticalMerge(options.verticalMerge);
} else if (options.rowSpan && options.rowSpan > 1) {
// if cell already have a `verticalMerge`, don't handle `rowSpan`
this.properties.addVerticalMerge(VerticalMergeType.RESTART);
properties.addVerticalMerge(VerticalMergeType.RESTART);
}
if (options.margins) {
this.properties.addMargins(options.margins);
properties.addMargins(options.margins);
}
if (options.shading) {
this.properties.setShading(options.shading);
properties.setShading(options.shading);
}
if (options.columnSpan) {
this.properties.addGridSpan(options.columnSpan);
properties.addGridSpan(options.columnSpan);
}
if (options.width) {
this.properties.setWidth(options.width.size, options.width.type);
properties.setWidth(options.width.size, options.width.type);
}
if (options.borders) {
if (options.borders.top) {
this.properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color);
properties.Borders.addTopBorder(options.borders.top.style, options.borders.top.size, options.borders.top.color);
}
if (options.borders.bottom) {
this.properties.Borders.addBottomBorder(
options.borders.bottom.style,
options.borders.bottom.size,
options.borders.bottom.color,
);
properties.Borders.addBottomBorder(options.borders.bottom.style, options.borders.bottom.size, options.borders.bottom.color);
}
if (options.borders.left) {
this.properties.Borders.addLeftBorder(options.borders.left.style, options.borders.left.size, options.borders.left.color);
properties.Borders.addLeftBorder(options.borders.left.style, options.borders.left.size, options.borders.left.color);
}
if (options.borders.right) {
this.properties.Borders.addRightBorder(
options.borders.right.style,
options.borders.right.size,
options.borders.right.color,
);
properties.Borders.addRightBorder(options.borders.right.style, options.borders.right.size, options.borders.right.color);
}
}
}