Table Class
Defines a table in the document.
#Declaration
export class Table extends TableElementBase
#Remarks
richEdit.beginUpdate();
richEdit.history.beginTransaction();
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var columnCount = 5;
var rowCount = 5;
var table = subDocument.tables.create(position, columnCount, rowCount);
for (var rowInd = 0, row; row = table.rows.getByIndex(rowInd); rowInd++) {
for (var cellInd = 0, cell; cell = row.cells.getByIndex(cellInd); cellInd++) {
subDocument.insertText(cell.interval.start, "Row[" + rowInd + "].Cell[" + cellInd + "]");
}
}
richEdit.history.endTransaction();
richEdit.endUpdate();
#Properties
#autoFit Property
Specifies whether the table automatically adjusts its width to fit content.
#Declaration
get autoFit(): boolean
set autoFit(value: boolean)
#Property Value
Type | Description |
---|---|
boolean |
|
#Remarks
A table can automatically adjust its width to fit content. Use the autoFit
property to identify whether size adjustment is enabled.
#backgroundColor Property
Specifies the table’s background color.
#Declaration
get backgroundColor(): string
set backgroundColor(value: string)
#Property Value
Type | Description |
---|---|
string | The table’s background color. |
#Remarks
The backgroundColor
property allows you to obtain and change the table’s background color.
Note
A cell’s background (Table
#borders Property
Specifies the table’s border settings.
#Declaration
get borders(): TableBorders
set borders(value: ITableBorders)
#Property Value
Type | Description |
---|---|
Table |
Table border settings. |
#Remarks
Specify the borders
property to configure a table’s border settings.
#cellMargins Property
Specifies margin settings of all cells in the table.
#Declaration
get cellMargins(): Margins
set cellMargins(value: IMargins)
#Property Value
Type | Description |
---|---|
Margins | An object that contains margin settings. |
#Remarks
Use the cellMargins
property to access and customize the margins of all table cells.
Note
A cell’s margins property takes priority over the table’s cell
#contentHorizontalAlignment Property
Specifies the horizontal alignment of table content.
#Declaration
get contentHorizontalAlignment(): TableContentHorizontalAlignment | null
set contentHorizontalAlignment(value: TableContentHorizontalAlignment)
#Property Value
Type | Description |
---|---|
Table |
An enumeration value. |
#Remarks
Use the contentHorizontalAlignment
property to horizontally align content in all table cells.
Note
A cell’s content
#contentVerticalAlignment Property
Specifies the vertical alignment of table content.
#Declaration
get contentVerticalAlignment(): TableContentVerticalAlignment | null
set contentVerticalAlignment(value: TableContentVerticalAlignment)
#Property Value
Type | Description |
---|---|
Table |
An enumeration value. |
#Remarks
Use the contentHorizontalAlignment
property to horizontally align content in all table cells.
Note
A cell’s content
#index Property
Gets an index of the table.
#Declaration
get index(): number
#Property Value
Type | Description |
---|---|
number | The table’s index. |
#Remarks
Use the index to access the corresponding table by the TableCollection.getByIndex method.
#interval Property
Gets the text buffer interval occupied by the current table element.
#Declaration
get interval(): Interval
#Property Value
Type | Description |
---|---|
Interval | An object that contains the interval settings. |
#parentCell Property
Returns the cell that contains the current table.
#Declaration
get parentCell(): TableCell | null
#Property Value
Type | Description |
---|---|
Table |
The cell that contains the current table; |
#rows Property
Provides access to a collection of table rows.
#Declaration
get rows(): TableRowCollection
#Property Value
Type | Description |
---|---|
Table |
An array of Table |
#styleName Property
Specifies the table style name.
#Declaration
get styleName(): string
set styleName(value: string)
#Property Value
Type | Description |
---|---|
string | The table style name. |
#Remarks
Use the styleName
property to customize table appearance. Specify the tableStyleOptions property to apply/remove special formatting from the first, last, and odd columns and rows.
Note
Style options do not affect table appearance if the Normal Table or Grid Table Light style is applied to the table.
#tableStyleOptions Property
Specifies style options applied to the table.
#Declaration
get tableStyleOptions(): TableStyleOptions
set tableStyleOptions(value: TableStyleOptions)
#Property Value
Type | Description |
---|---|
Table |
Table style options. |
#Remarks
Specify the tableStyleOptions
property to apply/remove special formatting from the first, last, and odd columns and rows.
Note
Style options do not affect table appearance if the Normal Table or Grid Table Light style is applied to the table.
#width Property
Specifies the table’s width settings.
#Declaration
get width(): TableWidth
set width(value: TableWidth)
#Property Value
Type | Description |
---|---|
Table |
An object that contains width settings. |
#Remarks
Use the Table.width or TableCell.width property to specify the table or cell width.
#Methods
#delete Method
Deletes the current table.
#Declaration
delete(): void
#Remarks
var subDocument = richEdit.selection.activeSubDocument;
var position = richEdit.selection.active;
var tables = subDocument.tables.find(position);
for(var i = tables.length - 1, table; table = tables[i]; i--)
table.delete();
#mergeCells(startPosition, endPosition) Method
Merges all cells in the specified range.
#Declaration
mergeCells(
startPosition: TableCellPosition,
endPosition: TableCellPosition
): void
#Parameters
Name | Type | Description |
---|---|---|
start |
Table |
The position of the first cell in the range. |
end |
Table |
The position of the last cell in the range. |
#Remarks
A TableCellPosition object stores a cell’s position in the table. Pass two cell positions to the mergeCells
method to merge all cells in the specified range. The resulting cell has the same appearance settings as the first cell in the range.
The following code snippet merges 6 cells:
const subDocument = richEdit.selection.activeSubDocument;
const table = subDocument.tables.getByIndex(0);
const startCell = { rowIndex: 0, cellIndex: 0 };
const endCell = { rowIndex: 2, cellIndex: 1 };
table.mergeCells(startCell, endCell);