Class Table
Represents a table element within the document.
Implements
Inherited Members
Namespace: IronWord.Models
Assembly: IronWord.dll
Syntax
public class Table : TableElement, IEnumerable<TableCell>, IEnumerable, IEnumerable<TableRow>, ITable, IWordDocumentObject, IDocumentObject, ICloneable, IParent<IWordDocumentObjectCollection, IWordDocumentObject>
Constructors
Table()
Initializes a new instance of the Table class.
Declaration
public Table()
Table(TableRow[])
Initializes a new instance of the Table class with the specified rows.
Declaration
public Table(params TableRow[] rows)
Parameters
| Type | Name | Description |
|---|---|---|
| TableRow[] | rows | The table rows to be added. |
Table(Int32, Int32)
Initializes a new instance of the Table class with the specified number of rows and columns.
Declaration
public Table(int row, int column)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The number of rows in the table. |
| System.Int32 | column | The number of columns in each row of the table. |
Properties
BottomCellMargin
Gets or sets the margin between the bottom cell border and the cell contents.
Declaration
public Nullable<uint> BottomCellMargin { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.UInt32> |
Remarks
Stored in twips by default.
Columns
Gets the list of TableColumn elements contained within this table. Thread-safe implementation with double-checked locking for performance.
Declaration
public List<TableColumn> Columns { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<TableColumn> |
Data
Raw data
Declaration
public DataTable Data { get; }
Property Value
| Type | Description |
|---|---|
| System.Data.DataTable |
Direction
Gets or sets the text direction of the table.
Declaration
public Direction Direction { get; set; }
Property Value
| Type | Description |
|---|---|
| Direction |
Index
Gets the index of this table within the parent's list of children.
Declaration
public int Index { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Item[Int32]
Gets or sets the TableRow at the specified row index.
Declaration
public TableRow this[int row] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The index of the row. |
Property Value
| Type | Description |
|---|---|
| TableRow | The TableRow at the specified row index. |
Exceptions
| Type | Condition |
|---|---|
| System.IndexOutOfRangeException | Thrown when the specified row index is out of range. |
Item[Int32, Int32]
Gets or sets the TableCell at the specified row and column indices.
Declaration
public TableCell this[int row, int column] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The index of the row. |
| System.Int32 | column | The index of the column. |
Property Value
| Type | Description |
|---|---|
| TableCell | The TableCell at the specified row and column indices. |
Exceptions
| Type | Condition |
|---|---|
| System.IndexOutOfRangeException | Thrown when the specified row or column index is out of range. |
Justification
Gets or sets the justification of the text within the table.
Declaration
public Nullable<JustificationValues> Justification { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<IronSoftware.Abstractions.Word.JustificationValues> |
LeftCellMargin
Gets or sets the margin between the left cell border and the cell contents.
Declaration
public Nullable<uint> LeftCellMargin { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.UInt32> |
Remarks
Stored in twips by default.
MergedCells
Gets a list of cell merges applied to the table.
Declaration
public List<MergeCell> MergedCells { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<MergeCell> |
RightCellMargin
Gets or sets the margin between the right cell border and the cell contents.
Declaration
public Nullable<uint> RightCellMargin { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.UInt32> |
Remarks
Stored in twips by default.
Rows
Gets the list of TableRow elements contained within this table. Thread-safe implementation with caching for performance.
Declaration
public List<ITableRow> Rows { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<IronSoftware.Abstractions.Word.ITableRow> |
Shading
Gets or sets the Sets the color of the shading and fill of the table.
Declaration
public Shading Shading { get; set; }
Property Value
| Type | Description |
|---|---|
| Shading |
Style
Gets or sets the default styling of the table.
Declaration
public TableStyle Style { get; set; }
Property Value
| Type | Description |
|---|---|
| TableStyle |
Remarks
Any of these styling properties can be overridden by the styling of the table's rows and cells.
TopCellMargin
Gets or sets the margin between the top cell border and the cell contents.
Declaration
public Nullable<uint> TopCellMargin { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.UInt32> |
Remarks
Stored in twips by default.
Width
Gets or sets the width of the table.
Declaration
public Nullable<long> Width { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Int64> |
Remarks
Value is in twips by default.
Zebra
Gets or sets the pair of colors used for applying zebra background to table rows.
Declaration
public ZebraColor Zebra { get; set; }
Property Value
| Type | Description |
|---|---|
| ZebraColor |
Methods
AddColumn()
Adds a new column to the table.
Declaration
public Table AddColumn()
Returns
| Type | Description |
|---|---|
| Table |
AddRow(TableRow)
Initializes a new instance of the Table class with the specified row.
Declaration
public Table AddRow(TableRow row)
Parameters
| Type | Name | Description |
|---|---|---|
| TableRow | row | The table row to be added. |
Returns
| Type | Description |
|---|---|
| Table |
GetCell(Int32, Int32)
Gets the TableCell at the specified row and column indices.
Declaration
public TableCell GetCell(int row, int column)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The index of the row containing the desired TableCell. |
| System.Int32 | column | The index of the column containing the desired TableCell. |
Returns
| Type | Description |
|---|---|
| TableCell | The TableCell at the specified row and column indices. |
GetCellValue(Int32, Int32)
Gets the contents of a specific cell within the table.
Declaration
public List<IWordDocumentObject> GetCellValue(int rowIndex, int columnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | rowIndex | The row index of the cell. |
| System.Int32 | columnIndex | The column index of the cell. |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<IronSoftware.Abstractions.Word.IWordDocumentObject> | A list of ContentElement objects representing the cell's content. |
GetEnumerator()
Provides an enumerator that iterates through all TableCell elements in the table, traversing rows and cells.
Declaration
public IEnumerator<TableCell> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<TableCell> | An enumerator for the table cells. |
GetRow(Int32)
Gets the TableRow at the specified row indices.
Declaration
public TableRow GetRow(int row)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The index of the row in this table. |
Returns
| Type | Description |
|---|---|
| TableRow | The TableCell at the specified row and column indices. |
GetWidth(MeasurementUnit)
Gets the width of the Table in the specified measurement unit.
Declaration
public double GetWidth(MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| MeasurementUnit | measurementUnit | The measurement unit for the width. Default is twentieths of a point (Twips). |
Returns
| Type | Description |
|---|---|
| System.Double | The width of the Table in the specified measurement unit. |
MergeCells(Int32, Int32, Int32, Int32)
Merges a range of cells within the table.
Declaration
public Table MergeCells(int startRow, int startColumn, int endRow, int endColumn)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | startRow | The starting row index of the merged area (inclusive). |
| System.Int32 | startColumn | The starting column index of the merged area (inclusive). |
| System.Int32 | endRow | The ending row index of the merged area (inclusive). |
| System.Int32 | endColumn | The ending column index of the merged area (inclusive). |
Returns
| Type | Description |
|---|---|
| Table |
RemoveColumn(Int32)
Removes a column from the table.
Declaration
public Table RemoveColumn(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The index of the column to be removed. |
Returns
| Type | Description |
|---|---|
| Table |
RemoveRow(Int32)
Removes a row from the table.
Declaration
public Table RemoveRow(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | The index of the row to be removed. |
Returns
| Type | Description |
|---|---|
| Table |
SetCellValue(Int32, Int32, ContentElement)
Sets the content of a specific cell within the table.
Declaration
public Table SetCellValue(int row, int column, ContentElement content)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The row index of the cell. |
| System.Int32 | column | The column index of the cell. |
| ContentElement | content | The ContentElement object representing the new content for the cell. |
Returns
| Type | Description |
|---|---|
| Table |
SetWidth(Double, MeasurementUnit)
Sets the width of the table.
Declaration
public Table SetWidth(double width, MeasurementUnit measurementUnit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | width | The width value to set. |
| MeasurementUnit | measurementUnit | The measurement unit of the provided height. Default is twentieths of a point (Twips). |
Returns
| Type | Description |
|---|---|
| Table |
Split(Int32, Int32, Int32, Int32)
Splits a cell in the table into multiple rows and columns.
Declaration
public Table Split(int row, int column, int toRow, int toColumn)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | row | The index of the starting row to split. |
| System.Int32 | column | The index of the starting column to split. |
| System.Int32 | toRow | The number of the row for the split. |
| System.Int32 | toColumn | The number of columns for the split. |
Returns
| Type | Description |
|---|---|
| Table |