Merge pull request #424 from seiya-git/master

fix set table cell width
This commit is contained in:
Dolan
2019-10-12 20:11:30 +01:00
committed by GitHub
2 changed files with 36 additions and 1 deletions

View File

@ -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: [],

View File

@ -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);