WordTable
OfficeIMO.Word
Represents a table within a WordDocument.
Inheritance
- WordElement
- WordTable
Usage
Explore 48 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 39
- Method WordDocument.AddTable
- Method WordDocument.AddTable``1
- Method WordDocument.CreateTable
- Method WordDocument.InsertTableAfter
- Property WordDocument.Tables
- Property WordDocument.TablesIncludingNestedTables
- Method WordFooter.AddTable
- Property WordFooter.Tables
- Method WordHeader.AddTable
- Property WordHeader.Tables
- Method WordHeaderFooter.AddTable
- Property WordHeaderFooter.Tables
- Method WordPaperStyle.AddCountTable
- Method WordPaperStyle.AddKeyValueTable
- Method WordPaperStyle.AddMetrics
- Method WordParagraph.AddTableAfter
- Method WordParagraph.AddTableBefore
- Method WordSection.AddTable
- Property WordSection.Tables
- Property WordSection.TablesIncludingNestedTables
- Method WordTable.AutoFitToContents
- Method WordTable.AutoFitToWindow
- Method WordTable.Clone
- Method WordTable.CloneAfterSelf
- Method WordTable.CloneBeforeSelf
- Method WordTable.Create
- Method WordTable.DistributeColumnsEvenly
- Method WordTable.SetCellText
- Method WordTable.SetColumnWidthsPercentage
- Method WordTable.SetFixedWidth
- Method WordTable.SetStyle
- Method WordTable.SetStyleId
- Method WordTable.SetWidthPercentage
- Property WordTable.NestedTables
- Property WordTable.ParentTable
- Method WordTableCell.AddTable
- Property WordTableCell.NestedTables
- Property WordTableCell.ParentTable
- Property WordTableRow.Parent
Accepted by parameters 9
- Method WordDocument.InsertTableAfter
- Method WordMailMerge.ExecuteTableRowGroups
- Method WordMailMerge.ExecuteTableRows
- Method WordPaperStyle.ApplyCountTable
- Method WordPaperStyle.ApplyKeyValueTable
- Method WordPaperStyle.ApplyTable
- Method WordPaperStyle.FitTableColumnsToHeaders
- Method WordTable.Clone
- Constructor WordTableRow.WordTableRow
Methods
public WordComment AddComment(string author, string initials, string comment) #Add comment to a Table
Parameters
- author string
- Provide an author of the comment
- initials string
- Provide initials of an author
- comment string
- Provide comment to insert
Returns
WordCommentpublic WordTableRow AddRow(int cellsCount = 0) #Add row to an existing table with the specified number of columns
Parameters
- cellsCount int = 0
Returns
WordTableRowpublic List<WordTableRow> AddRows(int rowCount, int cellCount) #Add specified number of rows to an existing table with the specified number of columns
Parameters
- rowCount int
- Number of rows to append.
- cellCount int
- Cells per row; zero uses the existing column count.
Returns
List<WordTableRow>public WordTable AutoFitToWindow() #Sets the table to AutoFit to Window (100% width)
Returns
WordTablepublic WordTableConditionalFormattingBuilder BeginConditionalFormatting() #Starts building conditional formatting rules using a fluent API.
public WordTable Clone() #Creates a deep copy of the current table and inserts it after the table.
Examples
WordTable clone = table.Clone();public WordTable Clone(WordParagraph paragraph, bool after = true) #Clones the table and inserts it relative to the specified paragraph.
Parameters
- paragraph OfficeIMO.Word.WordParagraph
- Reference paragraph for insertion.
- after bool = true
- If true inserts after the paragraph, otherwise before.
Examples
WordTable copy = table.Clone(paragraph, after: false);public WordTable Clone(WordTable table, bool after = true) #Clones the table and inserts it relative to another table.
Parameters
- table OfficeIMO.Word.WordTable
- Reference table for insertion.
- after bool = true
- If true inserts after the table, otherwise before.
Examples
WordTable copy = table1.Clone(table2, after: true);public WordTable CloneAfterSelf() #Clones the table and inserts the clone after the current table.
Examples
WordTable copy = table.CloneAfterSelf();public WordTable CloneBeforeSelf() #Clones the table and inserts the clone before the current table.
Examples
WordTable copy = table.CloneBeforeSelf();public void ConditionalFormatting(string columnName, string? matchText, WordTextMatchType matchType, OfficeColor? matchFillColor = null, OfficeColor? matchFontColor = null, OfficeColor? noMatchFillColor = null, OfficeColor? noMatchFontColor = null, bool ignoreCase = true, IEnumerable<string>? highlightColumns = null, Action<WordParagraph>? matchTextFormat = null, Action<WordParagraph>? noMatchTextFormat = null) #Applies conditional formatting to cells based on text contained in a specific column.
Parameters
- columnName string
- Header text of the column to evaluate.
- matchText string?
- Text to compare against cell content.
- matchType OfficeIMO.Word.WordTextMatchType
- Comparison operator.
- matchFillColor OfficeIMO.OfficeColor? = null
- Background color applied when condition is met.
- matchFontColor OfficeIMO.OfficeColor? = null
- Font color applied when condition is met.
- noMatchFillColor OfficeIMO.OfficeColor? = null
- Background color applied when condition is not met.
- noMatchFontColor OfficeIMO.OfficeColor? = null
- Font color applied when condition is not met.
- ignoreCase bool = true
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable<string>? = null
- Additional columns to apply the formatting to.
- matchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null
- Optional action applied to paragraphs when the condition is met.
- noMatchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null
- Optional action applied to paragraphs when the condition is not met.
public void ConditionalFormatting(IEnumerable<ValueTuple<string, string, WordTextMatchType>> conditions, bool matchAll, OfficeColor? matchFillColor = null, OfficeColor? matchFontColor = null, OfficeColor? noMatchFillColor = null, OfficeColor? noMatchFontColor = null, bool ignoreCase = true, IEnumerable<string>? highlightColumns = null, Action<WordParagraph>? matchTextFormat = null, Action<WordParagraph>? noMatchTextFormat = null) #Applies conditional formatting based on values in multiple columns.
Parameters
- conditions System.Collections.Generic.IEnumerable<System.ValueTuple<string, string, OfficeIMO.Word.WordTextMatchType>>
- List of column/value conditions.
- matchAll bool
- When true, all conditions must match; otherwise any condition can match.
- matchFillColor OfficeIMO.OfficeColor? = null
- Background color applied when conditions match.
- matchFontColor OfficeIMO.OfficeColor? = null
- Font color applied when conditions match.
- noMatchFillColor OfficeIMO.OfficeColor? = null
- Background color applied when conditions do not match.
- noMatchFontColor OfficeIMO.OfficeColor? = null
- Font color applied when conditions do not match.
- ignoreCase bool = true
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable<string>? = null
- Columns to apply the formatting to. Defaults to the columns used in conditions.
- matchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null
- Optional action applied to paragraphs when conditions match.
- noMatchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null
- Optional action applied to paragraphs when conditions do not match.
public void ConditionalFormatting(Func<WordTableRow, bool> predicate, Action<WordTableRow> matchAction, Action<WordTableRow>? noMatchAction = null) #Applies conditional formatting based on a custom row predicate.
Parameters
- predicate System.Func<OfficeIMO.Word.WordTableRow, bool>
- Condition evaluated for each data row.
- matchAction System.Action<OfficeIMO.Word.WordTableRow>
- Action executed when predicate is true.
- noMatchAction System.Action<OfficeIMO.Word.WordTableRow>? = null
- Action executed when predicate is false.
public WordTableRow CopyRow(WordTableRow row) #Copy existing WordTableRow and inserts it as a last row in a Table
Parameters
- row OfficeIMO.Word.WordTableRow
Returns
WordTableRowpublic static WordTable Create(WordDocument document, int rows, int columns, WordTableStyle tableStyle = TableGrid) #Creates a table instance without inserting it into the document.
Parameters
- document OfficeIMO.Word.WordDocument
- Parent WordDocument.
- rows int
- Number of rows.
- columns int
- Number of columns.
- tableStyle OfficeIMO.Word.WordTableStyle = TableGrid
- Style to apply to the table.
public WordTable DistributeColumnsEvenly() #Distribute columns evenly by setting their size to the same value based on the current table width settings (or 100% Pct if not set).
Returns
WordTablepublic IReadOnlyList<WordTableCell> InsertColumn(int index, params object?[] values) #Inserts a column at a zero-based grid column and returns its cells in row order. Inside a merged or spanned cell the column widens that cell, which is the cell returned for the row and receives its value.
Parameters
- index int
- values object?[]
Returns
IReadOnlyList<WordTableCell>public WordTableRow InsertRow(int index, params object?[] values) #Inserts a row at a zero-based logical index, including rows inside content controls and custom XML. The row spans the table's grid columns; inside a vertical merge it joins the merged cell, and that column's value is added to the merged cell.
Parameters
- index int
- values object?[]
Returns
WordTableRowpublic void MergeCells(int rowIndex, int columnIndex, int rowSpan, int colSpan, bool copyParagraphs = false) #Merges a rectangular range of cells.
Parameters
- rowIndex int
- Zero-based starting row index.
- columnIndex int
- Zero-based starting column index.
- rowSpan int
- Number of rows spanned by the merged region.
- colSpan int
- Number of columns spanned by the merged region.
- copyParagraphs bool = false
- If set to true, paragraphs from merged cells are copied into the first cell.
public void NormalizeForOnline() #Normalizes this table for online viewers by updating tblGrid only. Does not change authoring semantics (tblW, width type, positioning). Skips pure-Auto tables (keeps Word's native behavior): - no table preferred width (or Auto), - no column width type set, - and all cells carry only the library's default tcW (DXA 2400).
public WordTable SetCellText(int rowIndex, int columnIndex, string? text, bool bold = false) #Replaces the content of the first paragraph in an indexed cell with a single text run. This is the allocation-efficient path for filling rectangular reports; use WordTableRow.Cells when richer cell content is required.
Parameters
- rowIndex int
- Zero-based row index.
- columnIndex int
- Zero-based cell index within the row.
- text string?
- Text to place in the cell.
- bold bool = false
- Whether the new run is bold.
public WordTable SetColumnWidthsPercentage(params int[] percentages) #Sets column widths using percentages. Values are scaled proportionally when they don't sum to 100.
Parameters
- percentages int[]
- Column percentages in any positive ratio.
Returns
WordTablepublic WordTable SetFixedWidth(int percentage) #Sets the table to Fixed Width with the specified percentage
Parameters
- percentage int
- Width percentage (0-100)
Returns
WordTablepublic WordTable SetStyle(WordStyle style) #Applies a table style defined in this table's document.
Parameters
- style OfficeIMO.Word.WordStyle
- A table style from WordDocument.Styles.
Exceptions
ArgumentException– The style is not a table style of this document.
public WordTable SetStyleId(string styleId) #Applies a table style defined in the document.
Parameters
- styleId string
- Identifier of the table style to apply.
Inherited Methods
Properties
public List<WordParagraph> Paragraphs { get; } #Gets all WordParagraph instances contained in the table.
public bool AllowRowToBreakAcrossPages { get; set; } #Allow row to break across pages This sets each row to allow page break You can set each row separately as well Getting value returns true if any row allows page break For complete control use WordTableRow.AllowRowToBreakAcrossPages
public bool RepeatAsHeaderRowAtTheTopOfEachPage { get; set; } #Allow Header to repeat on each page This applies to only header of the table (first row)
public WordTableStyle? Style { get; set; } #Gets or sets the built-in table style applied to this table. Returns null when no built-in style is assigned. Set null to remove the style reference.
public WordTableAlignment? Alignment { get; set; } #Gets or sets the horizontal alignment of the table within the page. Logical start/end values read from a document resolve using the table's declared direction.
public WordTableWidth? Width { get; set; } #Gets or sets the directly authored preferred width. Null removes tblW and preserves the grid.
public bool? ConditionalFormattingFirstRow { get; set; } #Specifies that the first row conditional formatting shall be applied to the table.
public bool? ConditionalFormattingLastRow { get; set; } #Specifies that the last row conditional formatting shall be applied to the table.
public bool? ConditionalFormattingFirstColumn { get; set; } #Specifies that the first column conditional formatting shall be applied to the table.
public bool? ConditionalFormattingLastColumn { get; set; } #Specifies that the last column conditional formatting shall be applied to the table.
public bool? ConditionalFormattingNoHorizontalBand { get; set; } #Specifies that the horizontal banding conditional formatting shall not be applied to the table.
public bool? ConditionalFormattingNoVerticalBand { get; set; } #Specifies that the vertical banding conditional formatting shall not be applied to the table.
public bool RepeatHeaderRowAtTheTopOfEachPage { get; set; } #Specifies that the first row shall be repeated at the top of each page on which the table is displayed.
public List<WordTableRow> Rows { get; } #Gets the table's rows in document order, including rows inside content controls and custom XML.
public WordTablePosition Position { get; } #Provides positioning information for the table within the document.
public WordTableStyleDetails? StyleDetails { get; } #Gets direct table formatting settings, including tables without a named style.
public string? Title { get; set; } #Gets or sets a Title/Caption to a Table
public string? Description { get; set; } #Gets or sets Description for a Table
public WordTableLayoutMode LayoutMode { get; set; } #Gets or sets the layout algorithm used by Word for the table. Changing the algorithm preserves the table and cell preferred widths. Use WordTable.AutoFitToWindow or WordTable.SetFixedWidth when the width should also change.
public bool AllowTextWrap { get; set; } #Allow text to wrap around table.
public bool WrapText { get; set; } #Gets or sets whether text wraps within all cells of the table.
public bool FitText { get; set; } #Gets or sets whether text is compressed to fit within all cells of the table.
public List<OfficeLength> GridColumnWidth { get; set; } #Gets or sets physical grid geometry independently of preferred widths.
public List<WordTableWidth?> ColumnWidth { get; set; } #Gets first-row positional cell preferences, including absent slots, or applies preferences to each row.
public List<OfficeLength?> RowHeight { get; set; } #Gets declared row heights, including absent constraints, or applies exact heights in row order.
public List<WordTableCell> Cells { get; } #Get all WordTableCells in a table. A short way to loop thru all cells
public bool HasNestedTables { get; } #Gets information whether the Table has other nested tables in at least one of the TableCells
public List<WordTable> NestedTables { get; } #Get all nested tables in the table
public bool IsNestedTable { get; } #Gets information whether the table is nested table (within TableCell)
public WordTable? ParentTable { get; } #Gets nested table parent table if table is nested table
public List<WordStructuredDocumentTag> StructuredDocumentTags { get; } #Gets all structured document tags contained in the table, including nested tables.
public List<WordCheckBox> CheckBoxes { get; } #Gets all checkbox content controls contained in the table, including nested tables.
public List<WordDatePicker> DatePickers { get; } #Gets all date picker content controls contained in the table, including nested tables.
public List<WordDropDownList> DropDownLists { get; } #Gets all dropdown list content controls contained in the table, including nested tables.
public List<WordRepeatingSection> RepeatingSections { get; } #Gets all repeating section content controls contained in the table, including nested tables.