API Reference
WordTable
Represents a table within a WordDocument.
Inheritance
- WordElement
- WordTable
Constructors
WordTable(OfficeIMO.Word.WordDocument document, DocumentFormat.OpenXml.Wordprocessing.Table table) #Used during load of the document
Parameters
- document OfficeIMO.Word.WordDocument
- table DocumentFormat.OpenXml.Wordprocessing.Table
public WordTable(WordDocument document, TableCell wordTableCell, Int32 rows, Int32 columns, WordTableStyle tableStyle) #Initializes a new instance of WordTable and optionally inserts it into the document.
Parameters
- document OfficeIMO.Word.WordDocument
- Parent document.
- rows System.Int32
- Number of rows.
- columns System.Int32
- Number of columns.
- tableStyle OfficeIMO.Word.WordTableStyle
- Style applied to the table.
- insert System.Boolean
- If set to true the table is appended to the document immediately.
WordTable(OfficeIMO.Word.WordDocument document, DocumentFormat.OpenXml.Wordprocessing.TableCell wordTableCell, System.Int32 rows, System.Int32 columns, OfficeIMO.Word.WordTableStyle tableStyle) #Initializes a new instance of WordTable inside the specified TableCell.
Parameters
- document OfficeIMO.Word.WordDocument
- Parent document.
- wordTableCell DocumentFormat.OpenXml.Wordprocessing.TableCell
- Table cell that will host the table.
- rows System.Int32
- Number of rows.
- columns System.Int32
- Number of columns.
- tableStyle OfficeIMO.Word.WordTableStyle
- Style applied to the table.
Methods
AddCells(OfficeIMO.Word.WordTableRow row, System.Int32 cellsCount) #Add cells to an existing row
Parameters
- row OfficeIMO.Word.WordTableRow
- cellsCount System.Int32
public Void AddComment(String author, String initials, String comment) #VoidAdd comment to a Table
Parameters
- author System.String
- Provide an author of the comment
- initials System.String
- Provide initials of an author
- comment System.String
- Provide comment to insert
public WordTableRow AddRow(Int32 cellsCount = 0) #WordTableRowAdd row to an existing table with the specified number of columns
Parameters
- cellsCount System.Int32 = 0
public List<WordTableRow> AddRow(Int32 rowsCount, Int32 cellsCount) #List<WordTableRow>Add specified number of rows to an existing table with the specified number of columns
Parameters
- rowsCount System.Int32
- cellsCount System.Int32
AddRow(OfficeIMO.Word.WordTableRow row) #Adds a row to the table using WordTableRow object
Parameters
- row OfficeIMO.Word.WordTableRow
AdjustColumnWidthsBasedOnContent() #Analyzes the content of each cell and adjusts column widths accordingly
ApplyCalculatedWidths(System.Collections.Generic.List{System.Int32} columnWidths) #Applies the calculated column widths to the table
Parameters
- columnWidths System.Collections.Generic.List{System.Int32}
- List of column widths in DXA units
public WordTableConditionalFormattingBuilder BeginConditionalFormatting() #WordTableConditionalFormattingBuilderStarts building conditional formatting rules using a fluent API.
Returns
CalculateTextWidth(OfficeIMO.Word.WordParagraph paragraph) #Calculates approximate text width based on content
Parameters
- paragraph OfficeIMO.Word.WordParagraph
- The paragraph to analyze
Returns
Estimated width in DXA units
CheckTableProperties() #Generate table properties for the table if it doesn't exists
public WordTable Clone() #WordTableCreates a deep copy of the current table and inserts it after the table.
Returns
The newly cloned WordTable.
Examples
WordTable clone = table.Clone();
public WordTable Clone(WordTable table, Boolean after = true) #WordTableClones the table and inserts it relative to the specified paragraph.
Parameters
- paragraph OfficeIMO.Word.WordParagraph
- Reference paragraph for insertion.
- after System.Boolean = true
- If true inserts after the paragraph, otherwise before.
Returns
The cloned WordTable.
Examples
WordTable copy = table.Clone(paragraph, after: false);
Clone(OfficeIMO.Word.WordTable table, System.Boolean after) #Clones the table and inserts it relative to another table.
Parameters
- table OfficeIMO.Word.WordTable
- Reference table for insertion.
- after System.Boolean
- If true inserts after the table, otherwise before.
Returns
The cloned WordTable.
Examples
WordTable copy = table1.Clone(table2, after: true);
public WordTable CloneAfterSelf() #WordTableClones the table and inserts the clone after the current table.
Returns
The cloned WordTable.
Examples
WordTable copy = table.CloneAfterSelf();
public WordTable CloneBeforeSelf() #WordTableClones the table and inserts the clone before the current table.
Returns
The cloned WordTable.
Examples
WordTable copy = table.CloneBeforeSelf();
public Void ConditionalFormatting(String columnName, String matchText, TextMatchType matchType, Color matchFillColor, Nullable<Color> matchFontColor = null, Nullable<Color> noMatchFillColor = null, Nullable<Color> noMatchFontColor = null, Boolean ignoreCase = true, IEnumerable<String> highlightColumns = null, Action<WordParagraph> matchTextFormat = null, Action<WordParagraph> noMatchTextFormat = null) #VoidApplies conditional formatting to cells based on text contained in a specific column.
Parameters
- columnName System.String
- Header text of the column to evaluate.
- matchText System.String
- Text to compare against cell content.
- matchType OfficeIMO.Word.TextMatchType
- Comparison operator.
- matchFillColorHex System.String = null
- Background color applied when condition is met.
- matchFontColorHex System.String = null
- Font color applied when condition is met.
- noMatchFillColorHex System.String = null
- Background color applied when condition is not met.
- noMatchFontColorHex System.String = null
- Font color applied when condition is not met.
- ignoreCase System.Boolean = true
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable{System.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.
ConditionalFormatting(System.String columnName, System.String matchText, OfficeIMO.Word.TextMatchType matchType, SixLabors.ImageSharp.Color matchFillColor, System.Nullable{SixLabors.ImageSharp.Color} matchFontColor, System.Nullable{SixLabors.ImageSharp.Color} noMatchFillColor, System.Nullable{SixLabors.ImageSharp.Color} noMatchFontColor, System.Boolean ignoreCase, System.Collections.Generic.IEnumerable{System.String} highlightColumns, System.Action{OfficeIMO.Word.WordParagraph} matchTextFormat, System.Action{OfficeIMO.Word.WordParagraph} noMatchTextFormat) #Applies conditional formatting to cells using Color parameters.
Parameters
- columnName System.String
- Header text of the column to evaluate.
- matchText System.String
- Text to compare against cell content.
- matchType OfficeIMO.Word.TextMatchType
- Comparison operator.
- matchFillColor SixLabors.ImageSharp.Color
- Background color applied when condition is met.
- matchFontColor System.Nullable{SixLabors.ImageSharp.Color}
- Font color applied when condition is met.
- noMatchFillColor System.Nullable{SixLabors.ImageSharp.Color}
- Background color applied when condition is not met.
- noMatchFontColor System.Nullable{SixLabors.ImageSharp.Color}
- Font color applied when condition is not met.
- ignoreCase System.Boolean
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable{System.String}
- Additional columns to apply the formatting to.
- matchTextFormat System.Action{OfficeIMO.Word.WordParagraph}
- Optional action applied to paragraphs when the condition is met.
- noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph}
- Optional action applied to paragraphs when the condition is not met.
public Void ConditionalFormatting(IEnumerable<ValueTuple<String, String, TextMatchType>> conditions, Boolean matchAll, Color matchFillColor, Nullable<Color> matchFontColor = null, Nullable<Color> noMatchFillColor = null, Nullable<Color> noMatchFontColor = null, Boolean ignoreCase = true, IEnumerable<String> highlightColumns = null, Action<WordParagraph> matchTextFormat = null, Action<WordParagraph> noMatchTextFormat = null) #VoidApplies conditional formatting based on values in multiple columns.
Parameters
- conditions System.Collections.Generic.IEnumerable{System.ValueTuple{System.String,System.String,OfficeIMO.Word.TextMatchType}}
- List of column/value conditions.
- matchAll System.Boolean
- When true, all conditions must match; otherwise any condition can match.
- matchFillColorHex System.String = null
- Background color applied when conditions match.
- matchFontColorHex System.String = null
- Font color applied when conditions match.
- noMatchFillColorHex System.String = null
- Background color applied when conditions do not match.
- noMatchFontColorHex System.String = null
- Font color applied when conditions do not match.
- ignoreCase System.Boolean = true
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable{System.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.
ConditionalFormatting(System.Collections.Generic.IEnumerable{System.ValueTuple{System.String,System.String,OfficeIMO.Word.TextMatchType}} conditions, System.Boolean matchAll, SixLabors.ImageSharp.Color matchFillColor, System.Nullable{SixLabors.ImageSharp.Color} matchFontColor, System.Nullable{SixLabors.ImageSharp.Color} noMatchFillColor, System.Nullable{SixLabors.ImageSharp.Color} noMatchFontColor, System.Boolean ignoreCase, System.Collections.Generic.IEnumerable{System.String} highlightColumns, System.Action{OfficeIMO.Word.WordParagraph} matchTextFormat, System.Action{OfficeIMO.Word.WordParagraph} noMatchTextFormat) #Applies conditional formatting based on values in multiple columns using Color parameters.
Parameters
- conditions System.Collections.Generic.IEnumerable{System.ValueTuple{System.String,System.String,OfficeIMO.Word.TextMatchType}}
- List of column/value conditions.
- matchAll System.Boolean
- When true, all conditions must match; otherwise any condition can match.
- matchFillColor SixLabors.ImageSharp.Color
- Background color applied when conditions match.
- matchFontColor System.Nullable{SixLabors.ImageSharp.Color}
- Font color applied when conditions match.
- noMatchFillColor System.Nullable{SixLabors.ImageSharp.Color}
- Background color applied when conditions do not match.
- noMatchFontColor System.Nullable{SixLabors.ImageSharp.Color}
- Font color applied when conditions do not match.
- ignoreCase System.Boolean
- Whether comparison should ignore case.
- highlightColumns System.Collections.Generic.IEnumerable{System.String}
- Columns to apply the formatting to. Defaults to the columns used in conditions.
- matchTextFormat System.Action{OfficeIMO.Word.WordParagraph}
- Optional action applied to paragraphs when conditions match.
- noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph}
- Optional action applied to paragraphs when conditions do not match.
public Void ConditionalFormatting(Func<WordTableRow, Boolean> predicate, Action<WordTableRow> matchAction, Action<WordTableRow> noMatchAction = null) #VoidApplies conditional formatting based on a custom row predicate.
Parameters
- predicate System.Func{OfficeIMO.Word.WordTableRow,System.Boolean}
- 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.
ConvertHorizontalMergesToGridSpan() #Converts w:hMerge (restart/continue) patterns to w:gridSpan and removes the continued cells. Many online viewers ignore hMerge but support gridSpan.
public WordTableRow CopyRow(WordTableRow row) #WordTableRowCopy existing WordTableRow and inserts it as a last row in a Table
Parameters
- row OfficeIMO.Word.WordTableRow
public static WordTable Create(WordDocument document, Int32 rows, Int32 columns, WordTableStyle tableStyle = TableGrid) #WordTableCreates a table instance without inserting it into the document.
Parameters
- document OfficeIMO.Word.WordDocument
- Parent WordDocument.
- rows System.Int32
- Number of rows.
- columns System.Int32
- Number of columns.
- tableStyle OfficeIMO.Word.WordTableStyle = TableGrid
- Style to apply to the table.
Returns
The newly created WordTable.
public Void DistributeColumnsEvenly() #VoidDistribute columns evenly by setting their size to the same value based on the current table width settings (or 100% Pct if not set).
EnsureFirstRowTopBorder() #Ensures the parent cell of a nested table has at least the provided top/bottom padding (cell margins) so the inner table does not touch the borders vertically. No effect for non-nested tables. Applied conservatively (only when current value is null or 0).
EstimateContainingCellContentWidthInDxa() #Estimates the available content width of the containing table cell (for nested tables). Falls back to page content width when structure cannot be determined.
EstimateContentAreaWidthInDxa() #Returns the estimated text area width (page width minus left/right margins) in DXA. Uses the first section when the owning section can't be easily resolved.
EstimateContentWidth(OfficeIMO.Word.WordTableCell cell) #Estimates the width of content in a cell
Parameters
- cell OfficeIMO.Word.WordTableCell
- The table cell to analyze
Returns
Estimated width in DXA units
EstimateTableWidthInDxa() #Estimates the effective table width in DXA (twips) based on Table.Width/WidthType and the section page width/margins.
GetBestAvailableColumnWidths(System.Nullable{DocumentFormat.OpenXml.Wordprocessing.TableWidthUnitValues}@ arg1, System.Int32 arg2) #Attempts to derive a complete set of column widths and their unit by scanning rows. Prefer any row that has widths for all columns; fall back to the first row with any widths.
Parameters
- arg1 System.Nullable{DocumentFormat.OpenXml.Wordprocessing.TableWidthUnitValues}@
- arg2 System.Int32
public WordTableLayoutType GetCurrentLayoutType() #WordTableLayoutTypeGets the current table layout mode based on its properties
Returns
The current WordTableLayoutType
public Void MergeCells(Int32 rowIndex, Int32 columnIndex, Int32 rowSpan, Int32 colSpan, Boolean copyParagraphs = false) #VoidMerges a rectangular range of cells.
Parameters
- rowIndex System.Int32
- Zero-based starting row index.
- columnIndex System.Int32
- Zero-based starting column index.
- rowSpan System.Int32
- Number of rows spanned by the merged region.
- colSpan System.Int32
- Number of columns spanned by the merged region.
- copyParagraphs System.Boolean = false
- If set to true, paragraphs from merged cells are copied into the first cell.
public Void NormalizeForOnline() #VoidNormalizes 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).
RefreshGrid() #Exposed for internal callers in this assembly that change table structure (e.g., InsertColumn) and need to update the tblGrid.
RefreshTblGridFromColumnWidths() #Rebuilds the table grid (w:tblGrid) using DXA widths derived from current column width values/types and the table preferred width. Many consumers (Word Online, Google Docs) rely primarily on tblGrid when laying out columns and ignore cell tcW percentages. Keeping tblGrid in sync avoids the observed 50/50 column issue.
public Void SetColumnWidthsPercentage(params Int32[] percentages) #VoidSets column widths using percentages. Values are scaled proportionally when they don't sum to 100.
Parameters
- percentages System.Int32[]
- Column percentages in any positive ratio.
public Void SetFixedWidth(Int32 percentage) #VoidSets the table to Fixed Width with the specified percentage
Parameters
- percentage System.Int32
- Width percentage (0-100)
public WordTable SetStyleId(String styleId) #WordTableApplies a table style defined in the document.
Parameters
- styleId System.String
- Identifier of the table style to apply.
Returns
The current WordTable instance.
public Void SetTableLayout(WordTableLayoutType layoutType, Nullable<Int32> percentage = null) #VoidSets the table layout with proper AutoFit options
Parameters
- layoutType OfficeIMO.Word.WordTableLayoutType
- Type of layout to apply
- percentage System.Nullable{System.Int32} = null
- Optional percentage for fixed width (0-100)
public Void SetWidthPercentage(Int32 percentage) #VoidSets the table width to a percentage of the window width
Parameters
- percentage System.Int32
- Width percentage (0-100)
Inherited Methods
public override Boolean Equals(Object obj) #BooleanParameters
- obj Object
Properties
public List<WordParagraph> Paragraphs { get; } #Gets all WordParagraph instances contained in the table.
public Boolean 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 Boolean RepeatAsHeaderRowAtTheTopOfEachPage { get; set; } #Allow Header to repeat on each page This applies to only header of the table (first row)
public Nullable<WordTableStyle> Style { get; set; } #Gets or sets the built-in table style applied to this table. Returns null when no style is assigned.
public Nullable<TableRowAlignmentValues> Alignment { get; set; } #Gets or sets the horizontal alignment of the table within the page.
public Nullable<TableWidthUnitValues> WidthType { get; set; } #Gets or sets the unit type used by the Width property.
public Nullable<Int32> Width { get; set; } #Gets or sets width of a table
public Nullable<TableLayoutValues> LayoutType { get; set; } #Gets or sets layout of a table
public Nullable<Boolean> ConditionalFormattingFirstRow { get; set; } #Specifies that the first row conditional formatting shall be applied to the table.
public Nullable<Boolean> ConditionalFormattingLastRow { get; set; } #Specifies that the last row conditional formatting shall be applied to the table.
public Nullable<Boolean> ConditionalFormattingFirstColumn { get; set; } #Specifies that the first column conditional formatting shall be applied to the table.
public Nullable<Boolean> ConditionalFormattingLastColumn { get; set; } #Specifies that the last column conditional formatting shall be applied to the table.
public Nullable<Boolean> ConditionalFormattingNoHorizontalBand { get; set; } #Specifies that the horizontal banding conditional formatting shall not be applied to the table.
public Nullable<Boolean> ConditionalFormattingNoVerticalBand { get; set; } #Specifies that the vertical banding conditional formatting shall not be applied to the table.
public Boolean RepeatHeaderRowAtTheTopOfEachPage { get; set; } #Specifies that the first row shall be repeated at the top of each page on which the table is displayed.
public Int32 RowsCount { get; } #Gets the number of rows in the table.
public List<WordTableRow> Rows { get; } #Gets the collection of rows belonging to the table.
public WordTableRow FirstRow { get; } #Gets the first row of the table.
public WordTableRow LastRow { get; } #Gets the last row of the table.
public WordTableStyleDetails StyleDetails { get; } #Gets the table style details. WIP
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 Boolean AllowOverlap { get; set; } #Allow table to overlap or not
public WordTableLayoutType LayoutMode { get; set; } #Gets or sets the effective layout mode of the table using WordTableLayoutType enum. Setting FixedWidth via this property defaults to 100% width. Use SetFixedWidth(percentage) for specific percentages.
public WordTableLayoutType AutoFit { get; set; } #Gets or sets the AutoFit behavior for the table. Alias for LayoutMode.
public Boolean AllowTextWrap { get; set; } #Allow text to wrap around table.
public Boolean WrapText { get; set; } #Gets or sets whether text wraps within all cells of the table.
public Boolean FitText { get; set; } #Gets or sets whether text is compressed to fit within all cells of the table.
public List<Int32> GridColumnWidth { get; set; } #Sets or gets grid columns width (not really doing anything as far as I can see)
public List<Int32> ColumnWidth { get; set; } #Gets or sets column width for a whole table simplifying setup of column width Please note that it assumes first row has the same width as the rest of rows which may give false positives if there are multiple values set differently.
public Nullable<TableWidthUnitValues> ColumnWidthType { get; set; } #Gets or sets the column width type for a whole table simplifying setup of column width
public List<Int32> RowHeight { get; set; } #Get or set row heights for the table
public List<WordTableCell> Cells { get; } #Get all WordTableCells in a table. A short way to loop thru all cells
public Boolean 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 Boolean 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.
public List<WordCheckBox> CheckBoxes { get; } #Gets all checkbox content controls contained in the table.
public List<WordDatePicker> DatePickers { get; } #Gets all date picker content controls contained in the table.
public List<WordDropDownList> DropDownLists { get; } #Gets all dropdown list content controls contained in the table.
public List<WordRepeatingSection> RepeatingSections { get; } #Gets all repeating section content controls contained in the table.
Fields
public WordTablePosition Position #Provides positioning information for the table within the document.