ApiTable

new ApiTable()

Class representing a table.

Methods

Name Description
AddCaption

Adds a caption paragraph after (or before) the current table. Please note that the current table must be in the document (not in the footer/header). And if the current table is placed in a shape, then a caption is added after (or before) the parent shape.

AddColumn

Adds a new column to the current table.

AddColumns

Adds the new columns to the current table.

AddComment

Adds a comment to all contents of the current table. Please note that this table must be in the document.

AddElement

Adds a paragraph or a table or a blockLvl content control using its position in the cell.

AddRow

Adds a new row to the current table.

AddRows

Adds the new rows to the current table.

Clear

Clears the content from the table.

Copy

Creates a copy of the current table.

Delete

Deletes the current table.

GetCell

Returns a cell by its position.

GetClassType

Returns a type of the ApiTable class.

GetNext

Returns the next table if exists.

GetParentContentControl

Returns a content control that contains the current table.

GetParentTable

Returns a table that contains the current table.

GetParentTableCell

Returns a table cell that contains the current table.

GetPosInParent

Returns the table position within its parent element.

GetPrevious

Returns the previous table if exists.

GetRange

Returns a Range object that represents the part of the document contained in the specified table.

GetRow

Returns a table row by its position in the table.

GetRowsCount

Returns a number of rows in the current table.

GetTableDescription

Returns the table description.

GetTables

Returns the tables that contain the current table.

GetTableTitle

Returns the table title (caption).

InsertInContentControl

Wraps the current table object with a content control.

MergeCells

Merges an array of cells. If the merge is done successfully, it will return the resulting merged cell, otherwise the result will be "null". The number of cells in any row and the number of rows in the current table may be changed.

RemoveColumn

Removes a table column with a specified cell.

RemoveRow

Removes a table row with a specified cell.

ReplaceByElement

Replaces the current table with a new element.

Search

Searches for a scope of a table object. The search results are a collection of ApiRange objects.

Select

Selects the current table.

SetBackgroundColor

Sets the background color to all cells in the current table.

SetCellSpacing

Specifies the default table cell spacing (the spacing between adjacent cells and the edges of the table).

SetHAlign

Sets the horizontal alignment to the table.

SetJc

Specifies the alignment of the current table with respect to the text margins in the current section.

SetPaddings

Sets the table paddings. If table is inline, then only left padding is applied.

SetShd

Specifies the shading which is applied to the extents of the current table.

SetStyle

Sets a style to the current table.

SetStyleColBandSize

Specifies a number of columns which will comprise each table column band for this table style.

SetStyleRowBandSize

Specifies a number of rows which will comprise each table row band for this table style.

SetTableBorderBottom

Sets the border which will be displayed at the bottom of the current table.

SetTableBorderInsideH

Specifies the border which will be displayed on all horizontal table cell borders which are not on the outmost edge of the parent table (all horizontal borders which are not the topmost or bottommost borders).

SetTableBorderInsideV

Specifies the border which will be displayed on all vertical table cell borders which are not on the outmost edge of the parent table (all vertical borders which are not the leftmost or rightmost borders).

SetTableBorderLeft

Sets the border which will be displayed on the left of the current table.

SetTableBorderRight

Sets the border which will be displayed on the right of the current table.

SetTableBorderTop

Sets the border which will be displayed at the top of the current table.

SetTableCellMarginBottom

Specifies an amount of space which will be left between the bottom extent of the cell contents and the border of all table cells within the parent table (or table row).

SetTableCellMarginLeft

Specifies an amount of space which will be left between the left extent of the cell contents and the left border of all table cells within the parent table (or table row).

SetTableCellMarginRight

Specifies an amount of space which will be left between the right extent of the cell contents and the right border of all table cells within the parent table (or table row).

SetTableCellMarginTop

Specifies an amount of space which will be left between the top extent of the cell contents and the top border of all table cells within the parent table (or table row).

SetTableDescription

Sets the table description.

SetTableInd

Specifies the indentation which will be added before the leading edge of the current table in the document (the left edge in the left-to-right table, and the right edge in the right-to-left table).

SetTableLayout

Specifies the algorithm which will be used to lay out the contents of the current table within the document.

SetTableLook

Specifies the conditional formatting components of the referenced table style (if one exists) which will be applied to the set of table rows with the current table-level property exceptions. A table style can specify up to six different optional conditional formats, for example, different formatting for the first column, which then can be applied or omitted from individual table rows in the parent table.

The default setting is to apply the row and column band formatting, but not the first row, last row, first column, or last column formatting.

SetTableTitle

Sets the table title (caption).

SetTextPr

Applies the text settings to the entire contents of the table.

SetVAlign

Sets the vertical alignment to the table.

SetWidth

Sets the preferred width to the current table. Tables are created with the ApiTable#SetWidth method properties set by default, which always override the ApiTablePr#SetWidth method properties. That is why there is no use to try and apply ApiTablePr#SetWidth. We recommend you to use the ApiTablePr#SetWidth method instead.

SetWrappingStyle

Sets the table wrapping style.

Split

Splits the cell into a given number of rows and columns.

ToJSON

Converts the ApiTable object into the JSON object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oTable = Api.CreateTable(5, 5);
oTable.SetWidth("percent", 100);
oTable.AddColumn(oTable.GetRow(0).GetCell(1), true);
oTable.AddRow(oTable.GetRow(1).GetCell(0), true);
var oCopyTable = oTable.Copy();
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered"));
oTable.SetStyle(oTableStyle);
var oParagraph = Api.CreateParagraph();
oParagraph.AddText("Merged cell");
var oCell = oTable.MergeCells([oTable.GetRow(1).GetCell(1), oTable.GetRow(1).GetCell(2), oTable.GetRow(2).GetCell(1), oTable.GetRow(2).GetCell(2)]);
oTable.AddElement(oCell, 0, oParagraph);
var oBlockLvlSdt = oTable.InsertInContentControl(1);
oDocument.AddElement(0, oBlockLvlSdt);
var sClassType = oTable.GetClassType();
oParagraph = oDocument.GetElement(0);
oParagraph.AddText("Class Type = " + sClassType);
var aSearch = oTable.Search("cell");
aSearch[0].SetBold(true);
oCopyTable.SetHAlign("center");
oCopyTable.SetTableBorderTop("single", 4, 0, 51, 51, 51);
oCopyTable.SetTableBorderBottom("single", 32, 0, 51, 51, 51);
oCopyTable.SetTableBorderLeft("single", 4, 0, 51, 51, 51);
oCopyTable.SetTableBorderRight("single", 4, 0, 51, 51, 51);
oCopyTable.SetTableBorderInsideV("single", 4, 0, 255, 111, 61);
oCopyTable.SetTableBorderInsideH("single", 4, 0, 255, 111, 61);
oDocument.Push(oCopyTable);
builder.SaveFile("docx", "ApiTable.docx");
builder.CloseFile();

Resulting document