OfficeIMO

API Reference

Class

WordTable

Namespace OfficeIMO.Word
Assembly OfficeIMO.Word

Represents a table within a WordDocument.

Inheritance

Constructors

WordTable 3 overloads
WordTable(OfficeIMO.Word.WordDocument document, DocumentFormat.OpenXml.Wordprocessing.Table table) #

Used during load of the document

Parameters

document OfficeIMO.Word.WordDocument required
table DocumentFormat.OpenXml.Wordprocessing.Table required
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 requiredposition: 0
Parent document.
rows System.Int32 requiredposition: 1
Number of rows.
columns System.Int32 requiredposition: 2
Number of columns.
tableStyle OfficeIMO.Word.WordTableStyle requiredposition: 3
Style applied to the table.
insert System.Boolean requiredposition: 4
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 required
Parent document.
wordTableCell DocumentFormat.OpenXml.Wordprocessing.TableCell required
Table cell that will host the table.
rows System.Int32 required
Number of rows.
columns System.Int32 required
Number of columns.
tableStyle OfficeIMO.Word.WordTableStyle required
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 required
cellsCount System.Int32 required
public Void AddComment(String author, String initials, String comment) #
Returns: Void

Add comment to a Table

Parameters

author System.String requiredposition: 0
Provide an author of the comment
initials System.String requiredposition: 1
Provide initials of an author
comment System.String requiredposition: 2
Provide comment to insert
AddRow 3 overloads
public WordTableRow AddRow(Int32 cellsCount = 0) #
Returns: WordTableRow

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

Parameters

cellsCount System.Int32 = 0 optionalposition: 0
public List<WordTableRow> AddRow(Int32 rowsCount, Int32 cellsCount) #
Returns: List<WordTableRow>

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

Parameters

rowsCount System.Int32 requiredposition: 0
cellsCount System.Int32 requiredposition: 1
AddRow(OfficeIMO.Word.WordTableRow row) #

Adds a row to the table using WordTableRow object

Parameters

row OfficeIMO.Word.WordTableRow required
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} required
List of column widths in DXA units
public Void AutoFitToContents() #
Returns: Void

Sets the table to AutoFit to Contents

public Void AutoFitToWindow() #
Returns: Void

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

public WordTableConditionalFormattingBuilder BeginConditionalFormatting() #
Returns: WordTableConditionalFormattingBuilder

Starts building conditional formatting rules using a fluent API.

Returns

A new WordTableConditionalFormattingBuilder.

CalculateTextWidth(OfficeIMO.Word.WordParagraph paragraph) #

Calculates approximate text width based on content

Parameters

paragraph OfficeIMO.Word.WordParagraph required
The paragraph to analyze

Returns

Estimated width in DXA units

CheckTableProperties() #

Generate table properties for the table if it doesn't exists

Clone 3 overloads
public WordTable Clone() #
Returns: WordTable

Creates 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) #
Returns: WordTable

Clones the table and inserts it relative to the specified paragraph.

Parameters

paragraph OfficeIMO.Word.WordParagraph requiredposition: 0
Reference paragraph for insertion.
after System.Boolean = true optionalposition: 1
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 required
Reference table for insertion.
after System.Boolean required
If true inserts after the table, otherwise before.

Returns

The cloned WordTable.

Examples


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

        
public WordTable CloneAfterSelf() #
Returns: WordTable

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

Returns

The cloned WordTable.

Examples


WordTable copy = table.CloneAfterSelf();

        
public WordTable CloneBeforeSelf() #
Returns: WordTable

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

Returns

The cloned WordTable.

Examples


WordTable copy = table.CloneBeforeSelf();

        
ConditionalFormatting 5 overloads
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) #
Returns: Void

Applies conditional formatting to cells based on text contained in a specific column.

Parameters

columnName System.String requiredposition: 0
Header text of the column to evaluate.
matchText System.String requiredposition: 1
Text to compare against cell content.
matchType OfficeIMO.Word.TextMatchType requiredposition: 2
Comparison operator.
matchFillColorHex System.String = null requiredposition: 3
Background color applied when condition is met.
matchFontColorHex System.String = null optionalposition: 4
Font color applied when condition is met.
noMatchFillColorHex System.String = null optionalposition: 5
Background color applied when condition is not met.
noMatchFontColorHex System.String = null optionalposition: 6
Font color applied when condition is not met.
ignoreCase System.Boolean = true optionalposition: 7
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable{System.String} = null optionalposition: 8
Additional columns to apply the formatting to.
matchTextFormat System.Action{OfficeIMO.Word.WordParagraph} = null optionalposition: 9
Optional action applied to paragraphs when the condition is met.
noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph} = null optionalposition: 10
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 required
Header text of the column to evaluate.
matchText System.String required
Text to compare against cell content.
matchType OfficeIMO.Word.TextMatchType required
Comparison operator.
matchFillColor SixLabors.ImageSharp.Color required
Background color applied when condition is met.
matchFontColor System.Nullable{SixLabors.ImageSharp.Color} required
Font color applied when condition is met.
noMatchFillColor System.Nullable{SixLabors.ImageSharp.Color} required
Background color applied when condition is not met.
noMatchFontColor System.Nullable{SixLabors.ImageSharp.Color} required
Font color applied when condition is not met.
ignoreCase System.Boolean required
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable{System.String} required
Additional columns to apply the formatting to.
matchTextFormat System.Action{OfficeIMO.Word.WordParagraph} required
Optional action applied to paragraphs when the condition is met.
noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph} required
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) #
Returns: Void

Applies conditional formatting based on values in multiple columns.

Parameters

conditions System.Collections.Generic.IEnumerable{System.ValueTuple{System.String,System.String,OfficeIMO.Word.TextMatchType}} requiredposition: 0
List of column/value conditions.
matchAll System.Boolean requiredposition: 1
When true, all conditions must match; otherwise any condition can match.
matchFillColorHex System.String = null requiredposition: 2
Background color applied when conditions match.
matchFontColorHex System.String = null optionalposition: 3
Font color applied when conditions match.
noMatchFillColorHex System.String = null optionalposition: 4
Background color applied when conditions do not match.
noMatchFontColorHex System.String = null optionalposition: 5
Font color applied when conditions do not match.
ignoreCase System.Boolean = true optionalposition: 6
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable{System.String} = null optionalposition: 7
Columns to apply the formatting to. Defaults to the columns used in conditions.
matchTextFormat System.Action{OfficeIMO.Word.WordParagraph} = null optionalposition: 8
Optional action applied to paragraphs when conditions match.
noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph} = null optionalposition: 9
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}} required
List of column/value conditions.
matchAll System.Boolean required
When true, all conditions must match; otherwise any condition can match.
matchFillColor SixLabors.ImageSharp.Color required
Background color applied when conditions match.
matchFontColor System.Nullable{SixLabors.ImageSharp.Color} required
Font color applied when conditions match.
noMatchFillColor System.Nullable{SixLabors.ImageSharp.Color} required
Background color applied when conditions do not match.
noMatchFontColor System.Nullable{SixLabors.ImageSharp.Color} required
Font color applied when conditions do not match.
ignoreCase System.Boolean required
Whether comparison should ignore case.
highlightColumns System.Collections.Generic.IEnumerable{System.String} required
Columns to apply the formatting to. Defaults to the columns used in conditions.
matchTextFormat System.Action{OfficeIMO.Word.WordParagraph} required
Optional action applied to paragraphs when conditions match.
noMatchTextFormat System.Action{OfficeIMO.Word.WordParagraph} required
Optional action applied to paragraphs when conditions do not match.
public Void ConditionalFormatting(Func<WordTableRow, Boolean> predicate, Action<WordTableRow> matchAction, Action<WordTableRow> noMatchAction = null) #
Returns: Void

Applies conditional formatting based on a custom row predicate.

Parameters

predicate System.Func{OfficeIMO.Word.WordTableRow,System.Boolean} requiredposition: 0
Condition evaluated for each data row.
matchAction System.Action{OfficeIMO.Word.WordTableRow} requiredposition: 1
Action executed when predicate is true.
noMatchAction System.Action{OfficeIMO.Word.WordTableRow} = null optionalposition: 2
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) #
Returns: WordTableRow

Copy existing WordTableRow and inserts it as a last row in a Table

Parameters

row OfficeIMO.Word.WordTableRow requiredposition: 0
public static WordTable Create(WordDocument document, Int32 rows, Int32 columns, WordTableStyle tableStyle = TableGrid) #
Returns: WordTable

Creates a table instance without inserting it into the document.

Parameters

document OfficeIMO.Word.WordDocument requiredposition: 0
Parent WordDocument.
rows System.Int32 requiredposition: 1
Number of rows.
columns System.Int32 requiredposition: 2
Number of columns.
tableStyle OfficeIMO.Word.WordTableStyle = TableGrid optionalposition: 3
Style to apply to the table.

Returns

The newly created WordTable.

public Void DistributeColumnsEvenly() #
Returns: Void

Distribute 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 required
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}@ required
arg2 System.Int32 required
public WordTableLayoutType GetCurrentLayoutType() #
Returns: WordTableLayoutType

Gets 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) #
Returns: Void

Merges a rectangular range of cells.

Parameters

rowIndex System.Int32 requiredposition: 0
Zero-based starting row index.
columnIndex System.Int32 requiredposition: 1
Zero-based starting column index.
rowSpan System.Int32 requiredposition: 2
Number of rows spanned by the merged region.
colSpan System.Int32 requiredposition: 3
Number of columns spanned by the merged region.
copyParagraphs System.Boolean = false optionalposition: 4
If set to true, paragraphs from merged cells are copied into the first cell.
public Void NormalizeForOnline() #
Returns: Void

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).

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 Remove() #
Returns: Void

Remove table from document

public Void SetColumnWidthsPercentage(params Int32[] percentages) #
Returns: Void

Sets column widths using percentages. Values are scaled proportionally when they don't sum to 100.

Parameters

percentages System.Int32[] requiredposition: 0
Column percentages in any positive ratio.
public Void SetFixedWidth(Int32 percentage) #
Returns: Void

Sets the table to Fixed Width with the specified percentage

Parameters

percentage System.Int32 requiredposition: 0
Width percentage (0-100)
public WordTable SetStyleId(String styleId) #
Returns: WordTable

Applies a table style defined in the document.

Parameters

styleId System.String requiredposition: 0
Identifier of the table style to apply.

Returns

The current WordTable instance.

public Void SetTableLayout(WordTableLayoutType layoutType, Nullable<Int32> percentage = null) #
Returns: Void

Sets the table layout with proper AutoFit options

Parameters

layoutType OfficeIMO.Word.WordTableLayoutType requiredposition: 0
Type of layout to apply
percentage System.Nullable{System.Int32} = null optionalposition: 1
Optional percentage for fixed width (0-100)
public Void SetWidthPercentage(Int32 percentage) #
Returns: Void

Sets the table width to a percentage of the window width

Parameters

percentage System.Int32 requiredposition: 0
Width percentage (0-100)

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.