From 1a1c1f26d9dc7192283f1ae55bb9fb07f0a0eb1c Mon Sep 17 00:00:00 2001 From: Dolan Date: Thu, 22 Mar 2018 22:55:33 +0000 Subject: [PATCH] Border for tables by default --- src/file/table/properties.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/file/table/properties.ts b/src/file/table/properties.ts index 2321429551..3e9bb43e24 100644 --- a/src/file/table/properties.ts +++ b/src/file/table/properties.ts @@ -5,6 +5,7 @@ export type WidthTypes = "dxa" | "pct" | "nil" | "auto"; export class TableProperties extends XmlComponent { constructor() { super("w:tblPr"); + this.root.push(new TableBorders()); } public setWidth(type: WidthTypes, w: number | string): TableProperties { @@ -46,3 +47,38 @@ class TableLayout extends XmlComponent { this.root.push(new TableLayoutAttributes({ type })); } } + +class TableBorders extends XmlComponent { + constructor() { + super("w:tblBorders"); + this.root.push(new TableBordersElement("w:top", "single", 4, 0, "auto")); + this.root.push(new TableBordersElement("w:left", "single", 4, 0, "auto")); + this.root.push(new TableBordersElement("w:bottom", "single", 4, 0, "auto")); + this.root.push(new TableBordersElement("w:right", "single", 4, 0, "auto")); + this.root.push(new TableBordersElement("w:insideH", "single", 4, 0, "auto")); + this.root.push(new TableBordersElement("w:insideV", "single", 4, 0, "auto")); + } +} + +class TableBordersElement extends XmlComponent { + constructor(elementName: string, value: string, size: number, space: number, color: string) { + super(elementName); + this.root.push( + new TableBordersAttributes({ + value, + size, + space, + color, + }), + ); + } +} + +class TableBordersAttributes extends XmlAttributeComponent<{ value: string; size: number; space: number; color: string }> { + protected xmlKeys = { + value: "w:val", + size: "w:sz", + space: "w:space", + color: "w:color", + }; +}