From 06abde24252318f199e275cdd36cc34283e65bf8 Mon Sep 17 00:00:00 2001 From: Seiya Date: Sat, 12 Oct 2019 02:06:17 +0300 Subject: [PATCH 1/2] fix set table cell width --- src/file/table/table-cell/table-cell.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index 5c34d17903..469331bc08 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -6,7 +6,7 @@ import { IXmlableObject, XmlComponent } from "file/xml-components"; import { ITableShadingAttributesProperties } from "../shading"; import { Table } from "../table"; import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins"; -import { VerticalAlign, VerticalMergeType } from "./table-cell-components"; +import { VerticalAlign, VerticalMergeType, WidthType } from "./table-cell-components"; import { TableCellProperties } from "./table-cell-properties"; export interface ITableCellOptions { @@ -14,6 +14,10 @@ export interface ITableCellOptions { readonly margins?: ITableCellMarginOptions; readonly verticalAlign?: VerticalAlign; readonly verticalMerge?: VerticalMergeType; + readonly width?: { + readonly size: number | string; + readonly type?: WidthType; + }; readonly columnSpan?: number; readonly rowSpan?: number; readonly borders?: { @@ -78,6 +82,10 @@ export class TableCell extends XmlComponent { this.properties.addVerticalMerge(VerticalMergeType.RESTART); } + if (options.width) { + this.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); From bfbe59cb84b9f124b303a86887d381fb55a07e5e Mon Sep 17 00:00:00 2001 From: Seiya Date: Sat, 12 Oct 2019 03:14:25 +0300 Subject: [PATCH 2/2] table cell width test --- src/file/table/table-cell/table-cell.spec.ts | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/file/table/table-cell/table-cell.spec.ts b/src/file/table/table-cell/table-cell.spec.ts index 4dd86ffc9c..a4c316f7ba 100644 --- a/src/file/table/table-cell/table-cell.spec.ts +++ b/src/file/table/table-cell/table-cell.spec.ts @@ -395,6 +395,33 @@ describe("TableCell", () => { }); }); + it("should create with width", () => { + const cell = new TableCell({ + children: [], + width: { size: 100, type: WidthType.DXA }, + }); + const tree = new Formatter().format(cell); + expect(tree).to.deep.equal({ + "w:tc": [ + { + "w:tcPr": [ + { + "w:tcW": { + _attr: { + "w:type": "dxa", + "w:w": 100, + }, + }, + }, + ], + }, + { + "w:p": {}, + }, + ], + }); + }); + it("should create with column span", () => { const cell = new TableCell({ children: [],