Add more changes to table API and documentation
This commit is contained in:
@ -9,7 +9,7 @@ const table = doc.createTable(4, 4);
|
|||||||
table
|
table
|
||||||
.getCell(2, 2)
|
.getCell(2, 2)
|
||||||
.addParagraph(new Paragraph("Hello"))
|
.addParagraph(new Paragraph("Hello"))
|
||||||
.Properties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
|
.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
|
||||||
.addBottomBorder(BorderStyle.DOUBLE, 3, "blue")
|
.addBottomBorder(BorderStyle.DOUBLE, 3, "blue")
|
||||||
.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green")
|
.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green")
|
||||||
.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||||
|
@ -9,7 +9,7 @@ const table = doc.createTable(2, 2);
|
|||||||
table
|
table
|
||||||
.getCell(1, 1)
|
.getCell(1, 1)
|
||||||
.addParagraph(new Paragraph("This text should be in the middle of the cell"))
|
.addParagraph(new Paragraph("This text should be in the middle of the cell"))
|
||||||
.Properties.setVerticalAlign(VerticalAlign.CENTER);
|
.setVerticalAlign(VerticalAlign.CENTER);
|
||||||
|
|
||||||
table
|
table
|
||||||
.getCell(1, 0)
|
.getCell(1, 0)
|
||||||
|
@ -40,14 +40,6 @@ const cell = table.getCell([ROW INDEX], [COLUMN INDEX]);
|
|||||||
const cell = table.getCell(0, 2);
|
const cell = table.getCell(0, 2);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cell Properties & Styling
|
|
||||||
|
|
||||||
With the cell's `Properties`, you csn change it's borders, set it's vertical alignment
|
|
||||||
|
|
||||||
```ts
|
|
||||||
cell.Properties;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Borders
|
## Borders
|
||||||
|
|
||||||
BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`.
|
BorderStyle can be imported from `docx`. Size determines the thickness. HTML color can be a hex code or alias such as `red`.
|
||||||
@ -80,16 +72,32 @@ cell.Borders.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
|||||||
## Set Width
|
## Set Width
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
table.setWidth([WIDTH], [OPTIONAL WidthType]);
|
import { WidthType } from "docx";
|
||||||
|
|
||||||
|
table.setWidth([WIDTH], [OPTIONAL WidthType. Defaults to DXA]);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
table.setWidth(4535, WidthType.DXA);
|
table.setWidth(4535, WidthType.DXA);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Vertical Align
|
## Vertical Align
|
||||||
|
|
||||||
## Borders
|
Sets the vertical alignment of the contents of the cell
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { VerticalAlign } from "docx";
|
||||||
|
|
||||||
|
cell.setVerticalAlign([VerticalAlign TYPE]);
|
||||||
|
```
|
||||||
|
|
||||||
|
For example, to center align a cell:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
cell.setVerticalAlign(VerticalAlign.CENTER);
|
||||||
|
```
|
||||||
|
|
||||||
## Rows
|
## Rows
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { Paragraph } from "file/paragraph";
|
|||||||
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
import { IXmlableObject, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { Table } from "../table";
|
import { Table } from "../table";
|
||||||
|
import { TableCellBorders, VerticalAlign } from "./table-cell-components";
|
||||||
import { TableCellProperties } from "./table-cell-properties";
|
import { TableCellProperties } from "./table-cell-properties";
|
||||||
|
|
||||||
export class TableCell extends XmlComponent {
|
export class TableCell extends XmlComponent {
|
||||||
@ -45,7 +46,19 @@ export class TableCell extends XmlComponent {
|
|||||||
return para;
|
return para;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get Properties(): TableCellProperties {
|
public setVerticalAlign(type: VerticalAlign): TableCell {
|
||||||
return this.properties;
|
this.properties.setVerticalAlign(type);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addGridSpan(cellSpan: number): TableCell {
|
||||||
|
this.properties.addGridSpan(cellSpan);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get Borders(): TableCellBorders {
|
||||||
|
return this.properties.Borders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ export class TableRow extends XmlComponent {
|
|||||||
|
|
||||||
public addGridSpan(index: number, cellSpan: number): TableCell {
|
public addGridSpan(index: number, cellSpan: number): TableCell {
|
||||||
const remainCell = this.cells[index];
|
const remainCell = this.cells[index];
|
||||||
remainCell.Properties.addGridSpan(cellSpan);
|
remainCell.addGridSpan(cellSpan);
|
||||||
this.cells.splice(index + 1, cellSpan - 1);
|
this.cells.splice(index + 1, cellSpan - 1);
|
||||||
this.root.splice(index + 2, cellSpan - 1);
|
this.root.splice(index + 2, cellSpan - 1);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user