Class WTable
Represents a table in the Word document.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Portable.dll
Syntax
public class WTable : TextBodyItem, IXDLSSerializable, ITextBodyItem, IWTable, ICompositeEntity, IEntity, ITableWidget, IWidget
Constructors
WTable(IWordDocument)
Initializes a new instance of the WTable class with the specified WordDocument instance.
Declaration
public WTable(IWordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The WordDocument instance. |
WTable(IWordDocument, Boolean)
Initializes a new instance of the WTable class with the specified WordDocument instance and show border option.
Declaration
public WTable(IWordDocument doc, bool showBorder)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The WordDocument instance. |
System.Boolean | showBorder | True if to show the table border; otherwise, false. |
Properties
ApplyStyleForBandedColumns
Gets or sets a value indicating whether to apply style bands to the columns in a table, if an applied preset table style provides style banding for columns.
Declaration
public bool ApplyStyleForBandedColumns { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for banded columns; otherwise, false. |
Examples
The following example illustrates how to apply style for banded columns of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Enable special formatting for banded columns of the table
table.ApplyStyleForBandedColumns = true;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Enable special formatting for banded columns of the table
table.ApplyStyleForBandedColumns = True
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyleForBandedRows
Gets or sets a value indicating whether to apply style bands to the rows in a table, if an applied preset table style provides style banding for rows. The default value is True.
Declaration
public bool ApplyStyleForBandedRows { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for banded rows; otherwise, false. |
Examples
The following example illustrates how to apply style for banded rows of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Disable special formatting for banded rows of the table
table.ApplyStyleForBandedRows = false;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Enable special formatting for banded rows of the table
table.ApplyStyleForBandedRows = False
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyleForFirstColumn
Gets or sets a value indicating whether to apply first-column formatting to the first column of the specified table. The default value is true.
Declaration
public bool ApplyStyleForFirstColumn { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for first column; otherwise, false. |
Examples
The following example illustrates how to apply style for first column of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Disable special formatting for first column of the table
table.ApplyStyleForFirstColumn = false;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Disable special formatting for first column of the table
table.ApplyStyleForFirstColumn = False
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyleForHeaderRow
Gets or sets a value indicating whether to apply heading-row formatting to the first row of the table. The default value is true.
Declaration
public bool ApplyStyleForHeaderRow { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for first row; otherwise, false. |
Examples
The following example illustrates how to apply style for header row of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Disable special formatting for header row of the table
table.ApplyStyleForHeaderRow = false;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Disable special formatting for header row of the table
table.ApplyStyleForHeaderRow = False
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyleForLastColumn
Gets or sets a value indicating whether to apply last-column formatting to the last column of the specified table..
Declaration
public bool ApplyStyleForLastColumn { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for last column; otherwise, false. |
Examples
The following example illustrates how to apply style for last column of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Enable special formatting for last column of the table
table.ApplyStyleForLastColumn = true;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Enable special formatting for last column of the table
table.ApplyStyleForLastColumn = True
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyleForLastRow
Gets or sets a value indicating whether to apply last-row formatting to the last row of the specified table.
Declaration
public bool ApplyStyleForLastRow { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | True if need to apply style for last row; otherwise, false. |
Examples
The following example illustrates how to apply style for last row of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
WTable table = section.Tables[0] as WTable;
//Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
//Enable special formatting for last row of the table
table.ApplyStyleForLastRow = false;
//Save and close the document
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Applies "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
'Enable special formatting for last row of the table
table.ApplyStyleForLastRow = True
'Save and close the document
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ChildEntities
Gets the child elements of the table.
Declaration
public EntityCollection ChildEntities { get; }
Property Value
Type | Description |
---|---|
EntityCollection | The collection of child elements. |
Description
Gets or sets the table description.
Declaration
public string Description { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the description of the table. |
EntityType
Gets the type of the entity. Read-only.
Declaration
public override EntityType EntityType { get; }
Property Value
Type | Description |
---|---|
EntityType | The EntityType of the current item. |
Overrides
FirstRow
Gets the first row in table. Read-only.
Declaration
public WTableRow FirstRow { get; }
Property Value
Type | Description |
---|---|
WTableRow | The WTableRow object that represents the first row in the table. |
Examples
The following example illustrates how to get the first row of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Get the last cell
WTableRow row = table.FirstRow;
//Apply text direction to the last cell
row.RowFormat.BackColor = Color.LightGray;
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Get the last cell
Dim row As WTableRow = table.FirstRow
'Apply text direction to the last cell
row.RowFormat.BackColor = Color.LightGray
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
IndentFromLeft
Gets or sets the indent from left for the table.
Declaration
public float IndentFromLeft { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float value that indicates the indent from left. |
Examples
The following example illustrates how to set the left indent for the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
//Add a new table into Word document
IWTable table = section.AddTable();
//Set number of rows and columns
table.ResetCells(2, 2);
//Set left indent for table.
table.IndentFromLeft = 10;
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
'Add a new table into Word document
Dim table As IWTable = section.AddTable()
'Set number of rows and columns
table.ResetCells(2, 2)
'Set left indent for table.
table.IndentFromLeft = 10
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Item[Int32, Int32]
Gets the table cell at the specified row and column index. Read-only.
Declaration
public WTableCell this[int row, int column] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | row | The integer that specifies the row index. |
System.Int32 | column | The integer that specifies the column index. |
Property Value
Type | Description |
---|---|
WTableCell | The WTableCell object at the specified index. |
Examples
The following example illustrates how to get the cell in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
//Add new table.
IWTable table = section.AddTable();
table.ResetCells(2, 2);
//Add content to table cell
table[0, 0].AddParagraph().AppendText("First row, First cell");
table[0, 1].AddParagraph().AppendText("First row, Second cell");
table[1, 0].AddParagraph().AppendText("Second row, First cell");
table[1, 1].AddParagraph().AppendText("Second row, Second cell");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Horizontal merging of Table cells")
'Add new table.
Dim table As IWTable = section.AddTable()
table.ResetCells(2, 2)
'Add content to table cell
table(0, 0).AddParagraph().AppendText("First row, First cell")
table(0, 1).AddParagraph().AppendText("First row, Second cell")
table(1, 0).AddParagraph().AppendText("Second row, First cell")
table(1, 1).AddParagraph().AppendText("Second row, Second cell")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The index is not valid in the table. |
LastCell
Gets the last cell in last row. Read-only.
Declaration
public WTableCell LastCell { get; }
Property Value
Type | Description |
---|---|
WTableCell | The WTableCell object that represents the last cell. |
Examples
The following example illustrates how to get the last cell of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Get the last cell
WTableCell cell = table.LastCell;
//Apply text direction to the last cell
cell.CellFormat.TextDirection = Syncfusion.DocIO.DLS.TextDirection.Vertical;
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Get the last cell
Dim cell As WTableCell = table.LastCell
'Apply text direction to the last cell
cell.CellFormat.TextDirection = Syncfusion.DocIO.DLS.TextDirection.Vertical
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
LastRow
Gets the last row in table. Read-only.
Declaration
public WTableRow LastRow { get; }
Property Value
Type | Description |
---|---|
WTableRow | The WTableRow object that represents the last row in the table. |
Examples
The following example illustrates how to get the last row of the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Get the last cell
WTableRow row = table.LastRow;
//Apply text direction to the last cell
row.RowFormat.BackColor = Color.LightGray;
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Get the last cell
Dim row As WTableRow = table.LastRow
'Apply text direction to the last cell
row.RowFormat.BackColor = Color.LightGray
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Rows
Gets the rows collection that represent all the rows in the table. Read-only.
Declaration
public WRowCollection Rows { get; }
Property Value
Type | Description |
---|---|
WRowCollection | The collection of rows in the table. |
See Also
StyleName
Gets the name of the table style. Read-only.
Declaration
public string StyleName { get; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the style name. |
TableFormat
Gets the table format. Read-only.
Declaration
public RowFormat TableFormat { get; }
Property Value
Type | Description |
---|---|
RowFormat | The RowFormat object that specifies the table format. |
Title
Gets or sets the table title.
Declaration
public string Title { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the title of the table. |
Width
Gets the width of the table(in points).
Declaration
public float Width { get; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the width of the table. |
Methods
AddRow()
Adds a new row to the table.
Declaration
public WTableRow AddRow()
Returns
Type | Description |
---|---|
WTableRow | The reference to the newly added WTableRow. |
Examples
The following example illustrates how to add new row to the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
section.AddParagraph().AppendText("Price Details");
section.AddParagraph();
//Add a new table into Word document
IWTable table = section.AddTable();
//Add the first row to table
WTableRow row = table.AddRow();
//Add the first cell into first row
WTableCell cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Apple");
//Add the second cell into first row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("$40");
//Add second row to table
row = table.AddRow(false);
//Add the first cell into first row
cell = row.Cells[0];
cell.AddParagraph().AppendText("Orange");
//Add the second cell into first row
cell = row.Cells[1];
cell.AddParagraph().AppendText("$30");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Price Details")
section.AddParagraph()
'Add a new table into Word document
Dim table As IWTable = section.AddTable()
'Add the first row to table
Dim row As WTableRow = table.AddRow()
'Add the first cell into first row
Dim cell As WTableCell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Apple")
'Add the second cell into first row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("$40")
'Add second row to table
row = table.AddRow(False)
'Add the first cell into first row
cell = row.Cells(0)
cell.AddParagraph().AppendText("Orange")
'Add the second cell into first row
cell = row.Cells(1)
cell.AddParagraph().AppendText("$30")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AddRow(Boolean)
Adds a new row to table specifying whether to have the same format as the previous row.
Declaration
public WTableRow AddRow(bool isCopyFormat)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isCopyFormat | True if to have the same format as previous row; otherwise, false. |
Returns
Type | Description |
---|---|
WTableRow | The reference to the newly added WTableRow. |
Examples
The following example illustrates how to add new row to the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
section.AddParagraph().AppendText("Price Details");
section.AddParagraph();
//Add a new table into Word document
IWTable table = section.AddTable();
//Add the first row to table
WTableRow row = table.AddRow();
//Add the first cell into first row
WTableCell cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Apple");
//Add the second cell into first row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("$40");
//Add second row to table
row = table.AddRow(false);
//Add the first cell into first row
cell = row.Cells[0];
cell.AddParagraph().AppendText("Orange");
//Add the second cell into first row
cell = row.Cells[1];
cell.AddParagraph().AppendText("$30");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Price Details")
section.AddParagraph()
'Add a new table into Word document
Dim table As IWTable = section.AddTable()
'Add the first row to table
Dim row As WTableRow = table.AddRow()
'Add the first cell into first row
Dim cell As WTableCell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Apple")
'Add the second cell into first row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("$40")
'Add second row to table
row = table.AddRow(False)
'Add the first cell into first row
cell = row.Cells(0)
cell.AddParagraph().AppendText("Orange")
'Add the second cell into first row
cell = row.Cells(1)
cell.AddParagraph().AppendText("$30")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
AddRow(Boolean, Boolean)
Adds a new row to table specifying whether to have the same format and cells count similar to the previous row.
Declaration
public WTableRow AddRow(bool isCopyFormat, bool autoPopulateCells)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isCopyFormat | True if to have the same format as previous row; otherwise, false. |
System.Boolean | autoPopulateCells | True if need to auto populate cells; otherwise, false. |
Returns
Type | Description |
---|---|
WTableRow | The reference to the newly added WTableRow. |
Examples
The following example illustrates how to add a row with formatting similar to the previous row.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
section.AddParagraph().AppendText("Price Details");
section.AddParagraph();
//Add a new table into Word document
IWTable table = section.AddTable();
//Add the first row into table
WTableRow row = table.AddRow();
//Add the first cell into first row
WTableCell cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Item");
//Add the second cell into first row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Price($)");
//Add the second row into table
row = table.AddRow(true, false);
//Add the first cell into second row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Apple");
//Add the second cell into second row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("50");
//Add the third row into table
row = table.AddRow(true, false);
//Add the first cell into third row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("Orange");
//Add the second cell into third row
cell = row.AddCell();
//Specify the cell width
cell.Width = 200;
cell.AddParagraph().AppendText("30");
document.Save("Table.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Price Details")
section.AddParagraph()
'Add a new table into Word document
Dim table As IWTable = section.AddTable()
'Add the first row into table
Dim row As WTableRow = table.AddRow()
'Add the first cell into first row
Dim cell As WTableCell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Item")
'Add the second cell into first row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Price($)")
'Add the second row into table
row = table.AddRow(True, False)
'Add the first cell into second row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Apple")
'Add the second cell into second row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("50")
'Add the third row into table
row = table.AddRow(True, False)
'Add the first cell into third row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("Orange")
'Add the second cell into third row
cell = row.AddCell()
'Specify the cell width
cell.Width = 200
cell.AddParagraph().AppendText("30")
document.Save("Table.docx", FormatType.Docx)
document.Close()
End Sub
ApplyHorizontalMerge(Int32, Int32, Int32)
Applies horizontal merge for table cells specified by the row index, start cell index and end cell index.
Declaration
public void ApplyHorizontalMerge(int rowIndex, int startCellIndex, int endCellIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowIndex | The integer specifies index of the row. |
System.Int32 | startCellIndex | The integer specifies start index of the cell. |
System.Int32 | endCellIndex | The integer specifies end index of the cell. |
Examples
The following example illustrates how to apply horizontal merge for the table cells.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
section.AddParagraph().AppendText("Vertical merging of Table cells");
IWTable table = section.AddTable();
table.ResetCells(5, 5);
//Specify the horizontal merge from second cell to fifth cell in third row
table.ApplyHorizontalMerge(2, 1, 4);
document.Save("HorizontalMerge.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Vertical merging of Table cells")
Dim table As IWTable = section.AddTable()
table.ResetCells(5, 5)
'Specify the horizontal merge from second cell to fifth cell in third row
table.ApplyHorizontalMerge(2, 1, 4)
document.Save("HorizontalMerge.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyle(BuiltinTableStyle)
Applies the built-in table style to the table.
Declaration
public void ApplyStyle(BuiltinTableStyle builtinTableStyle)
Parameters
Type | Name | Description |
---|---|---|
BuiltinTableStyle | builtinTableStyle | The BuiltinTableStyle to be applied for the table. |
Examples
The following example illustrates how to apply built-in style for the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load an existing Word document
WordDocument document = new WordDocument("Table.docx", FormatType.Docx);
WSection section = document.Sections[0];
//Get the table
WTable table = section.Tables[0] as WTable;
//Apply "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading);
document.Save("TableStyle.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load an existing Word document
Dim document As New WordDocument("Table.docx", FormatType.Docx)
Dim section As WSection = document.Sections(0)
'Get the table
Dim table As WTable = TryCast(section.Tables(0), WTable)
'Apply "LightShading" built-in style to table
table.ApplyStyle(BuiltinTableStyle.LightShading)
document.Save("TableStyle.docx", FormatType.Docx)
document.Close()
End Sub
ApplyStyle(String)
Declaration
public void ApplyStyle(string styleName)
Parameters
Type | Name | Description |
---|---|---|
System.String | styleName |
ApplyVerticalMerge(Int32, Int32, Int32)
Applies the vertical merge for table cells specified by the column index, start row index and end row index.
Declaration
public void ApplyVerticalMerge(int columnIndex, int startRowIndex, int endRowIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | columnIndex | The integer specifies index of the column. |
System.Int32 | startRowIndex | The integer specifies start index of the row. |
System.Int32 | endRowIndex | The integer specifies end index of the row. |
Examples
The following example illustrates how to apply vertical merge for the table cells.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
section.AddParagraph().AppendText("Vertical merging of Table cells");
IWTable table = section.AddTable();
table.ResetCells(5, 5);
//Specify the vertical merge to the third cell, from second row to fifth row
table.ApplyVerticalMerge(2, 1, 4);
document.Save("VerticalMerge.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
section.AddParagraph().AppendText("Vertical merging of Table cells")
Dim table As IWTable = section.AddTable()
table.ResetCells(5, 5)
'Specify the vertical merge to the third cell, from second row to fifth row
table.ApplyVerticalMerge(2, 1, 4)
document.Save("VerticalMerge.docx", FormatType.Docx)
document.Close()
End Sub
Clone()
Creates a duplicate copy of the table.
Declaration
public WTable Clone()
Returns
Type | Description |
---|---|
WTable | The reference to the newly created WTable object. |
CloneImpl()
Creates a duplicate copy of the table.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | The object that can be casted as WTable. |
Overrides
CreateLayoutInfo()
Creates layout information.
Declaration
protected override void CreateLayoutInfo()
Overrides
Find(Regex)
Returns first entry of the specified System.Text.RegularExpressions.Regex in the table.
Declaration
public override TextSelection Find(Regex pattern)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex that specifies the text to be found. |
Returns
Type | Description |
---|---|
TextSelection | The TextSelection object which represents the text found. |
Overrides
Examples
The following example illustrates how to find a text in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Find the text in the table
TextSelection selection = table.Find(new Regex("content"));
WTextRange text = selection.GetAsOneRange();
//Set the character format of the text found
text.CharacterFormat.AllCaps = true;
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Find the text in the table
Dim selection As TextSelection = table.Find(New Regex("content"))
Dim text As WTextRange = selection.GetAsOneRange()
'Set the character format of the text found
text.CharacterFormat.AllCaps = True
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
GetStyle()
Gets the style applied for the table.
Declaration
public IWTableStyle GetStyle()
Returns
Type | Description |
---|---|
IWTableStyle | The IWTableStyle of the current table. |
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()
Overrides
RemoveAbsPosition()
Removes the absolute position data, if the table has absolute position in the document.
Declaration
public void RemoveAbsPosition()
Replace(String, String, Boolean, Boolean)
Replaces all entries of given string in the table with replace string, taking into consideration case sensitive and whole word options.
Declaration
public override int Replace(string given, string replace, bool caseSensitive, bool wholeWord)
Parameters
Type | Name | Description |
---|---|---|
System.String | given | The string represents the text to be found. |
System.String | replace | The string specifies the text to replace. |
System.Boolean | caseSensitive | Set to true to match the case of the text similar to specified in the |
System.Boolean | wholeWord | Set to true to match the whole word of the text similar to specified in the |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace a text in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Replace the text
table.Replace("illustrates", "describes", true, true);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Replace the text
table.Replace("illustrates", "describes", True, True)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Replace(Regex, TextSelection)
Replaces the specified regular expression with a TextSelection in the table.
Declaration
public override int Replace(Regex pattern, TextSelection textSelection)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex used to find the text. |
TextSelection | textSelection | The TextSelection which specifies the text to replace. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace a text in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Get first paragraph
WParagraph paragraph = document.Sections[0].Paragraphs[0];
//Get the text using text selection
TextSelection selection = new TextSelection(paragraph, 0, 20);
//Replace the text
table.Replace(new Regex("illustrates"), selection);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Get first paragraph
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(0)
'Get the text using text selection
Dim selection As New TextSelection(paragraph, 0, 20)
'Replace the text
table.Replace(New Regex("illustrates"), selection)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Replace(Regex, TextSelection, Boolean)
Replaces all entries of given regular expression in the table with the TextSelection along with its formatting.
Declaration
public override int Replace(Regex pattern, TextSelection textSelection, bool saveFormatting)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex used to find the text. |
TextSelection | textSelection | The TextSelection which specifies the text to replace. |
System.Boolean | saveFormatting | Set to true if to save source formatting; otherwise, false. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace a text in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Get first paragraph
WParagraph paragraph = document.Sections[0].Paragraphs[0];
//Get the text using text selection
TextSelection selection = new TextSelection(paragraph, 0, 20);
//Replace the text
table.Replace(new Regex("illustrates"), selection, true);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Get first paragraph
Dim paragraph As WParagraph = document.Sections(0).Paragraphs(0)
'Get the text using text selection
Dim selection As New TextSelection(paragraph, 0, 20)
'Replace the text
table.Replace(New Regex("illustrates"), selection, True)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Replace(Regex, String)
Replaces all entries of given regular expression in the table with the replace string.
Declaration
public override int Replace(Regex pattern, string replace)
Parameters
Type | Name | Description |
---|---|---|
System.Text.RegularExpressions.Regex | pattern | The System.Text.RegularExpressions.Regex used to find the text. |
System.String | replace | The string specifies the text to replace. |
Returns
Type | Description |
---|---|
System.Int32 | The integer that represents the count of the replacements made. |
Overrides
Examples
The following example illustrates how to replace a text in the table.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template document
WordDocument document = new WordDocument("Template.docx");
//Get the table
WTable table = document.Sections[0].Tables[0] as WTable;
//Replace the text
table.Replace(new Regex("illustrates"), "describes");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template document
Dim document As New WordDocument("Template.docx")
'Get the table
Dim table As WTable = TryCast(document.Sections(0).Tables(0), WTable)
'Replace the text
table.Replace(New Regex("illustrates"), "describes")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
ResetCells(Int32, Int32)
Resets the table with the specified number of rows and columns.
Declaration
public void ResetCells(int rowsNum, int columnsNum)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowsNum | The integer specifies the number of rows. |
System.Int32 | columnsNum | The integer specifies the number of columns. |
Examples
The following example illustrates how to add a table to the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Gets the first section in the document
IWSection section = document.AddSection();
//Add new table to the section
IWTable table = section.AddTable();
//Set rows and columns count
table.ResetCells(2, 2);
//Add contents to the table
IWParagraph paragraph = table[0, 0].AddParagraph();
paragraph.AppendText("Apple");
paragraph = table[0, 1].AddParagraph();
paragraph.AppendText("Red");
paragraph = table[1, 0].AddParagraph();
paragraph.AppendText("Banana");
paragraph = table[1, 1].AddParagraph();
paragraph.AppendText("Yellow");
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Gets the first section in the document
Dim section As IWSection = document.AddSection()
'Add new table to the section
Dim table As IWTable = section.AddTable()
'Set rows and columns count
table.ResetCells(2, 2)
'Add contents to the table
Dim paragraph As IWParagraph = table(0, 0).AddParagraph()
paragraph.AppendText("Apple")
paragraph = table(0, 1).AddParagraph()
paragraph.AppendText("Red")
paragraph = table(1, 0).AddParagraph()
paragraph.AppendText("Banana")
paragraph = table(1, 1).AddParagraph()
paragraph.AppendText("Yellow")
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Exceptions
Type | Condition |
---|---|
System.ArgumentException | The number of cells must be between 1 and 63. |
ResetCells(Int32, Int32, RowFormat, Single)
Resets the table with the specified number of rows and columns, table format and cell width.
Declaration
public void ResetCells(int rowsNum, int columnsNum, RowFormat format, float cellWidth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | rowsNum | The integer specifies the number of rows. |
System.Int32 | columnsNum | The integer specifies the number of columns. |
RowFormat | format | The RowFormat specifies the format for the table. |
System.Single | cellWidth | The float specifies the width of the cells. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
//Add a new table into Word document
IWTable table = section.AddTable();
RowFormat format = new RowFormat();
format.BackColor = Color.LightGray;
format.CellSpacing = 2;
format.Paddings.All = 2;
//Set number of rows and columns
table.ResetCells(2, 2, format, 200);
//Save and close the document
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
'Add a new table into Word document
Dim table As IWTable = section.AddTable()
Dim format As New RowFormat()
format.BackColor = Color.LightGray
format.CellSpacing = 2
format.Paddings.All = 2
'Set number of rows and columns
table.ResetCells(2, 2, format, 200)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
WriteXmlAttributes(IXDLSAttributeWriter)
Writes object data as xml attributes.
Declaration
protected override void WriteXmlAttributes(IXDLSAttributeWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeWriter | writer | The IXDLSAttributeWriter object. |