Files
docx-js/src/file/table/table-properties/table-borders.ts

76 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-11-18 01:04:31 +00:00
// http://officeopenxml.com/WPtableBorders.php
import { BorderElement, BorderStyle, IBorderOptions } from "@file/border";
import { XmlComponent } from "@file/xml-components";
2018-10-23 23:44:50 +01:00
2019-11-18 01:04:31 +00:00
export interface ITableBordersOptions {
2021-05-23 07:14:00 +03:00
readonly top?: IBorderOptions;
readonly bottom?: IBorderOptions;
readonly left?: IBorderOptions;
readonly right?: IBorderOptions;
readonly insideHorizontal?: IBorderOptions;
readonly insideVertical?: IBorderOptions;
2019-11-18 01:04:31 +00:00
}
2021-05-23 07:14:00 +03:00
const NONE_BORDER = {
style: BorderStyle.NONE,
size: 0,
color: "auto",
};
const DEFAULT_BORDER = {
style: BorderStyle.SINGLE,
size: 4,
color: "auto",
};
2018-10-23 23:44:50 +01:00
export class TableBorders extends XmlComponent {
public static readonly NONE = {
2021-05-23 07:14:00 +03:00
top: NONE_BORDER,
bottom: NONE_BORDER,
left: NONE_BORDER,
right: NONE_BORDER,
insideHorizontal: NONE_BORDER,
insideVertical: NONE_BORDER,
};
2022-08-31 07:52:27 +01:00
public constructor(options: ITableBordersOptions) {
2018-10-23 23:44:50 +01:00
super("w:tblBorders");
2019-11-18 01:04:31 +00:00
if (options.top) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:top", options.top));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:top", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
if (options.left) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:left", options.left));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:left", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
if (options.bottom) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:bottom", options.bottom));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:bottom", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
if (options.right) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:right", options.right));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:right", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
if (options.insideHorizontal) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:insideH", options.insideHorizontal));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:insideH", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
if (options.insideVertical) {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:insideV", options.insideVertical));
2019-11-18 01:04:31 +00:00
} else {
2021-05-23 07:14:00 +03:00
this.root.push(new BorderElement("w:insideV", DEFAULT_BORDER));
2019-11-18 01:04:31 +00:00
}
2018-10-23 23:44:50 +01:00
}
}