Tables
- 4 minutes to read
RichEdit controls provide support for complex tables, as well as nested ones. An end-user can insert tables, edit a table layout by splitting and merging cells, and insert rows and columns. Borders and shading can be applied individually for each cell in a table.
RichEdit provides a set of commands to work with tables. These commands can be created and executed standalone. Command bars, menus or Ribbon interface make them available to end-users, as illustrated in the following picture.
The command bar provides end users with the ability to set borders, border color and cell shading.
#Table API
You can use Table API to add, delete or modify tables programmatically. Table in a document is represented by an object with the Table inteface. To get access to rows and cells, the TableRow and TableCell interfaces are implemented. Tables are arranged in a TableCollection collection, accessible via the SubDocument.Tables property.
To get access to table contents, use Range properties of cells, rows and a table. Once you've got a document range, you can operate with it using its own methods or via the Document or SubDocument methods.
#Commands
You can use various commands to handle tables in the document. Some commands are already represented as buttons in a default bar or Ribbon UI, while others could be attached to interface elements if required.
Table commands are listed below.
#Insert Table Elements
Command | Description |
---|---|
Insert |
Inserts a table at the selection. |
Insert |
Inserts a column to the left of the leftmost column in a selection. |
Insert |
Inserts a column to the right of the rightmost column in a selection. |
Insert |
Inserts a row in a table above the currently selected row. |
Insert |
Insert a row in a table below the currently selected row. |
Tab |
Adds a new row if the selection is in the last column of the last row in a table. |
#Delete Table Elements
Command | Description |
---|---|
Delete |
Deletes a selected table. |
Delete |
Deletes selected columns in a table. |
Delete |
Deletes selected rows in a table. |
#Merge and Split
Command | Description |
---|---|
Merge |
Merges selected cells. |
Split |
Splits a table at a selected row. |
#Invoke Dialog Windows
Command | Description |
---|---|
Show |
Invokes the 'Insert Cells' form used to select from the options to insert a cell, a row or a column. |
Show |
Invokes the 'Delete Cells' form used to select from the options to delete a cell, a row or a column. |
Show |
Invokes the 'Split Cells' form used to specify the number of columns and rows into which the cell should be split. |
#Show/Hide Borders
Command | Description |
---|---|
Toggle |
Toggles all borders for selected cells on/off. |
Toggle |
Toggles bottom borders for selected cells on/off. |
Toggle |
Toggles all inner borders for selected cells on/off. |
Toggle |
Toggles inner horizontal borders for selected cells on/off. |
Toggle |
Toggles inner vertical borders for selected cells on/off. |
Toggle |
Toggles left borders for selected cells on/off. |
Toggle |
Toggles outer borders for selected cells on/off. |
Toggle |
Toggles right borders for selected cells on/off. |
Toggle |
Toggles top borders for selected cells on/off. |
#Change Cell Alignment
Command | Description |
---|---|
Toggle |
Toggles bottom-center alignment for selected cells on/off. |
Toggle |
Toggles bottom-left alignment for selected cells on/off. |
Toggle |
Toggles bottom-right alignment for selected cells on/off. |
Toggle |
Toggles middle-center alignment for selected cells on/off. |
Toggle |
Toggles middle-left alignment for selected cells on/off. |
Toggle |
Toggles middle-right alignment for selected cells on/off. |
Toggle |
Toggles top-center alignment for selected cells on/off. |
Toggle |
Toggles top-left alignment for selected cells on/off. |
Toggle |
Toggles top-right alignment for selected cells on/off. |
#Miscellaneous
Command | Description |
---|---|
Select |
Selects an entire table in which a caret is located. |
Toggle |
Toggles displaying grid lines for a table with no borders applied - on/off. |