Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Class

WordTable

OfficeIMO.Word

Namespace
OfficeIMO.Word
Assembly
OfficeIMO.Word
Source revision
0eef6a5756b9 with working tree changes

Represents a table within a WordDocument.

Inheritance

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.

Accepted by parameters 9

Methods

public WordComment AddComment(string author, string initials, string comment) #

Add comment to a Table

Parameters

author string required
Provide an author of the comment
initials string required
Provide initials of an author
comment string required
Provide comment to insert
public WordTableRow AddRow(int cellsCount = 0) #

Add row to an existing table with the specified number of columns

Parameters

cellsCount int = 0 optional
public 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 required
Number of rows to append.
cellCount int required
Cells per row; zero uses the existing column count.

Returns

List<WordTableRow>
public WordTable AutoFitToContents() #

Sets the table to AutoFit to Contents

Returns

WordTable
public WordTable AutoFitToWindow() #

Sets the table to AutoFit to Window (100% width)

Returns

WordTable
public WordTableConditionalFormattingBuilder BeginConditionalFormatting() #

Starts building conditional formatting rules using a fluent API.

Clone 3 overloads
public WordTable Clone() #

Creates a deep copy of the current table and inserts it after the table.

Returns

WordTable The newly cloned WordTable.

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 required
Reference paragraph for insertion.
after bool = true optional
If true inserts after the paragraph, otherwise before.

Returns

WordTable The cloned WordTable.

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 required
Reference table for insertion.
after bool = true optional
If true inserts after the table, otherwise before.

Returns

WordTable The cloned WordTable.

Examples

WordTable copy = table1.Clone(table2, after: true);
public WordTable CloneAfterSelf() #

Clones the table and inserts the clone after the current table.

Returns

WordTable The cloned WordTable.

Examples

WordTable copy = table.CloneAfterSelf();
public WordTable CloneBeforeSelf() #

Clones the table and inserts the clone before the current table.

Returns

WordTable The cloned WordTable.

Examples

WordTable copy = table.CloneBeforeSelf();
ConditionalFormatting 3 overloads
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 required
Header text of the column to evaluate.
matchText string? required
Text to compare against cell content.
matchType OfficeIMO.Word.WordTextMatchType required
Comparison operator.
matchFillColor OfficeIMO.OfficeColor? = null optional
Background color applied when condition is met.
matchFontColor OfficeIMO.OfficeColor? = null optional
Font color applied when condition is met.
noMatchFillColor OfficeIMO.OfficeColor? = null optional
Background color applied when condition is not met.
noMatchFontColor OfficeIMO.OfficeColor? = null optional
Font color applied when condition is not met.
ignoreCase bool = true optional
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable<string>? = null optional
Additional columns to apply the formatting to.
matchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null optional
Optional action applied to paragraphs when the condition is met.
noMatchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null optional
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>> required
List of column/value conditions.
matchAll bool required
When true, all conditions must match; otherwise any condition can match.
matchFillColor OfficeIMO.OfficeColor? = null optional
Background color applied when conditions match.
matchFontColor OfficeIMO.OfficeColor? = null optional
Font color applied when conditions match.
noMatchFillColor OfficeIMO.OfficeColor? = null optional
Background color applied when conditions do not match.
noMatchFontColor OfficeIMO.OfficeColor? = null optional
Font color applied when conditions do not match.
ignoreCase bool = true optional
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable<string>? = null optional
Columns to apply the formatting to. Defaults to the columns used in conditions.
matchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null optional
Optional action applied to paragraphs when conditions match.
noMatchTextFormat System.Action<OfficeIMO.Word.WordParagraph>? = null optional
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> required
Condition evaluated for each data row.
matchAction System.Action<OfficeIMO.Word.WordTableRow> required
Action executed when predicate is true.
noMatchAction System.Action<OfficeIMO.Word.WordTableRow>? = null optional
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 required
public 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 required
Parent WordDocument.
rows int required
Number of rows.
columns int required
Number of columns.
tableStyle OfficeIMO.Word.WordTableStyle = TableGrid optional
Style to apply to the table.

Returns

WordTable The newly created WordTable.
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

WordTable
public 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 required
values object?[] required

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 required
values object?[] required
public void MergeCells(int rowIndex, int columnIndex, int rowSpan, int colSpan, bool copyParagraphs = false) #

Merges a rectangular range of cells.

Parameters

rowIndex int required
Zero-based starting row index.
columnIndex int required
Zero-based starting column index.
rowSpan int required
Number of rows spanned by the merged region.
colSpan int required
Number of columns spanned by the merged region.
copyParagraphs bool = false optional
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 void Remove() #

Remove table from document

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 required
Zero-based row index.
columnIndex int required
Zero-based cell index within the row.
text string? required
Text to place in the cell.
bold bool = false optional
Whether the new run is bold.

Returns

WordTable The current table for fluent use.
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[] required
Column percentages in any positive ratio.

Returns

WordTable
public WordTable SetFixedWidth(int percentage) #

Sets the table to Fixed Width with the specified percentage

Parameters

percentage int required
Width percentage (0-100)

Returns

WordTable
public WordTable SetStyle(WordStyle style) #

Applies a table style defined in this table's document.

Parameters

style OfficeIMO.Word.WordStyle required
A table style from WordDocument.Styles.

Returns

WordTable The current WordTable instance.

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 required
Identifier of the table style to apply.

Returns

WordTable The current WordTable instance.
public WordTable SetWidthPercentage(int percentage) #

Sets the table width to a percentage of the window width

Parameters

percentage int required
Width percentage (0-100)

Returns

WordTable

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 int RowCount { get; } #

Gets the number of rows in the table.

public List<WordTableRow> Rows { get; } #

Gets the table's rows in document order, including rows inside content controls and custom XML.

public WordTableRow FirstRow { get; } #

Gets the first row of the table.

public WordTableRow LastRow { get; } #

Gets the last row of the table.

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 bool AllowOverlap { get; set; } #

Allow table to overlap or not

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.