From 807605c0cc280e187d57515952f0ae738a1df112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E9=87=8C=E5=88=87=E7=BD=97?= Date: Fri, 27 Jul 2018 15:54:41 +0800 Subject: [PATCH] Add table cell Shading --- src/file/table/table-cell.ts | 24 ++++++++++++++++++++++++ src/file/table/table.ts | 8 +++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/file/table/table-cell.ts b/src/file/table/table-cell.ts index 5e64cc04b6..954786aa12 100644 --- a/src/file/table/table-cell.ts +++ b/src/file/table/table-cell.ts @@ -205,3 +205,27 @@ export class TableCellWidth extends XmlComponent { ); } } + +interface ITableCellShadingAttributesProperties { + fill?: string; + color?: string; + val?: string; +} + +class TableCellShadingAttributes extends XmlAttributeComponent { + protected xmlKeys = { + fill: "w:fill", + color: "w:color", + val: "w:val", + }; +} + +/** + * Table cell shading element. + */ +export class TableCellShading extends XmlComponent { + constructor(attrs: object) { + super("w:shd"); + this.root.push(new TableCellShadingAttributes(attrs)); + } +} diff --git a/src/file/table/table.ts b/src/file/table/table.ts index 2d19086baa..3837e9f79b 100644 --- a/src/file/table/table.ts +++ b/src/file/table/table.ts @@ -1,4 +1,4 @@ -import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "file/table/table-cell"; +import { GridSpan, TableCellBorders, TableCellWidth, TableCellShading, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "file/table/table-cell"; import { IXmlableObject, XmlComponent } from "file/xml-components"; import { Paragraph } from "../paragraph"; import { TableGrid } from "./grid"; @@ -159,4 +159,10 @@ export class TableCellProperties extends XmlComponent { return this; } + + public setShading(attrs: object): TableCellProperties { + this.root.push(new TableCellShading(attrs)); + + return this; + } }