Interface IWTable
Represents a table in a document.
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public interface IWTable : ICompositeEntity, IEntity
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
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
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
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
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
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
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
Description
Gets or sets the table description.
Declaration
string Description { get; set; }
Property Value
Type | Description |
---|---|
System.String | The string that specifies the description of the table. |
FirstRow
Gets the first row in table. Read-only.
Declaration
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
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
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
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
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
WRowCollection Rows { get; }
Property Value
Type | Description |
---|---|
WRowCollection | The collection of rows in the table. |
See Also
TableFormat
Gets the table format. Read-only.
Declaration
RowFormat TableFormat { get; }
Property Value
Type | Description |
---|---|
RowFormat | The RowFormat object that specifies the table format. |
Title
Gets or sets the table title.
Declaration
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
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
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
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
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
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
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
ApplyVerticalMerge(Int32, Int32, Int32)
Applies the vertical merge for table cells specified by the column index, start row index and end row index.
Declaration
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
GetStyle()
Gets the style applied for the table.
Declaration
IWTableStyle GetStyle()
Returns
Type | Description |
---|---|
IWTableStyle | The IWTableStyle of the current table. |
RemoveAbsPosition()
Removes the absolute position data, if the table has absolute position in the document.
Declaration
void RemoveAbsPosition()
ResetCells(Int32, Int32)
Resets the table with the specified number of rows and columns.
Declaration
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
ResetCells(Int32, Int32, RowFormat, Single)
Resets the table with the specified number of rows and columns, table format and cell width.
Declaration
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