From ca9ce01f5642ed46b411f0aa28e9fb1db6cd560c Mon Sep 17 00:00:00 2001 From: fmuscolino Date: Tue, 5 Mar 2019 10:39:18 +0100 Subject: [PATCH 1/3] Customize left and right cell borders (for Google Docs) --- .../table/table-cell/table-cell-components.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/file/table/table-cell/table-cell-components.ts b/src/file/table/table-cell/table-cell-components.ts index 7099fea33a..6fce6c9bad 100644 --- a/src/file/table/table-cell/table-cell-components.ts +++ b/src/file/table/table-cell/table-cell-components.ts @@ -66,6 +66,22 @@ export class TableCellBorders extends XmlComponent { return this; } + + public addLeftBorder(style: BorderStyle, size: number, color: string): TableCellBorders { + const left = new BaseTableCellBorder("w:left"); + left.setProperties(style, size, color); + this.root.push(left); + + return this; + } + + public addRightBorder(style: BorderStyle, size: number, color: string): TableCellBorders { + const right = new BaseTableCellBorder("w:right"); + right.setProperties(style, size, color); + this.root.push(right); + + return this; + } } /** From 441afe8c97dae87f2202ad8427ef7659a0d966e2 Mon Sep 17 00:00:00 2001 From: fmuscolino Date: Tue, 5 Mar 2019 11:34:43 +0100 Subject: [PATCH 2/3] Add tests --- src/file/table/table-cell/table-cell.spec.ts | 68 ++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/file/table/table-cell/table-cell.spec.ts b/src/file/table/table-cell/table-cell.spec.ts index a83b5812ad..5ec3344c30 100644 --- a/src/file/table/table-cell/table-cell.spec.ts +++ b/src/file/table/table-cell/table-cell.spec.ts @@ -102,12 +102,58 @@ describe("TableCellBorders", () => { }); }); + it("should add left border", () => { + const tb = new TableCellBorders(); + tb.addLeftBorder(BorderStyle.THICK, 3, "FF00FF"); + + const tree = new Formatter().format(tb); + expect(tree).to.deep.equal({ + "w:tcBorders": [ + { + "w:left": [ + { + _attr: { + "w:color": "FF00FF", + "w:sz": 3, + "w:val": "thick", + }, + }, + ], + }, + ], + }); + }); + + it("should add right border", () => { + const tb = new TableCellBorders(); + tb.addRightBorder(BorderStyle.THICK, 3, "FF00FF"); + + const tree = new Formatter().format(tb); + expect(tree).to.deep.equal({ + "w:tcBorders": [ + { + "w:right": [ + { + _attr: { + "w:color": "FF00FF", + "w:sz": 3, + "w:val": "thick", + }, + }, + ], + }, + ], + }); + }); + it("should add multiple borders", () => { const tb = new TableCellBorders(); tb.addTopBorder(BorderStyle.DOTTED, 1, "FF00FF"); tb.addEndBorder(BorderStyle.THICK, 3, "FF00FF"); tb.addBottomBorder(BorderStyle.DOUBLE, 1, "FF00FF"); tb.addStartBorder(BorderStyle.SINGLE, 2, "FF00FF"); + tb.addLeftBorder(BorderStyle.SINGLE, 2, "FF00FF"); + tb.addRightBorder(BorderStyle.SINGLE, 2, "FF00FF"); const tree = new Formatter().format(tb); expect(tree).to.deep.equal({ @@ -156,6 +202,28 @@ describe("TableCellBorders", () => { }, ], }, + { + "w:left": [ + { + _attr: { + "w:color": "FF00FF", + "w:sz": 2, + "w:val": "single", + }, + }, + ], + }, + { + "w:right": [ + { + _attr: { + "w:color": "FF00FF", + "w:sz": 2, + "w:val": "single", + }, + }, + ], + }, ], }); }); From 46ddf77342734a2610f51c3435531bd57f7807dc Mon Sep 17 00:00:00 2001 From: fmuscolino Date: Tue, 5 Mar 2019 11:38:21 +0100 Subject: [PATCH 3/3] Get cell properties --- src/file/table/table-cell/table-cell.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/file/table/table-cell/table-cell.ts b/src/file/table/table-cell/table-cell.ts index 3526e788bd..39fcbb83cc 100644 --- a/src/file/table/table-cell/table-cell.ts +++ b/src/file/table/table-cell/table-cell.ts @@ -61,4 +61,8 @@ export class TableCell extends XmlComponent { public get Borders(): TableCellBorders { return this.properties.Borders; } + + public get Properties(): TableCellProperties { + return this.properties; + } }