Class WTableCell
Represents a table cell.
Inheritance
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class WTableCell : WTextBody, IXDLSSerializable, ITextBody, IWidgetContainer, ICompositeEntity, IEntity, IWidget
Constructors
WTableCell(IWordDocument)
Initializes a new instance of the WTableCell class with the specified IWordDocument instance.
Declaration
public WTableCell(IWordDocument document)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | document | The IWordDocument instance. |
Properties
CellFormat
Gets the cell format. Read-only.
Declaration
public CellFormat CellFormat { get; }
Property Value
Type |
---|
CellFormat |
EntityType
Gets the type of the entity.
Declaration
public override EntityType EntityType { get; }
Property Value
Type | Description |
---|---|
EntityType | The EntityType of the current item. |
Overrides
GridSpan
Gets the number of grid columns spanned by the current cell. Read-only.
Declaration
public short GridSpan { get; }
Property Value
Type | Description |
---|---|
System.Int16 | The short specifies the number of grid columns in the parent table's table grid which shall be spanned by the current cell |
Remarks
GridSpan allows cells to have the appearance of being merged, as they span vertical boundaries of other cells in the table.
OwnerRow
Gets the owner row of the cell. Read-only.
Declaration
public WTableRow OwnerRow { get; }
Property Value
Type |
---|
WTableRow |
Examples
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("Cell"));
WTextRange text = selection.GetAsOneRange();
//Get the owner paragraph
WParagraph paragraph = text.OwnerParagraph;
//Get the owner cell
WTableCell cell = paragraph.OwnerTextBody as WTableCell;
//Get the index of the cell
int index = cell.GetCellIndex();
//Apply text direction to the next cell
WTableRow row = cell.OwnerRow;
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)
'Find the text in the table
Dim selection As TextSelection = table.Find(New Regex("Cell"))
Dim text As WTextRange = selection.GetAsOneRange()
'Get the owner paragraph
Dim paragraph As WParagraph = text.OwnerParagraph
'Get the owner cell
Dim cell As WTableCell = TryCast(paragraph.OwnerTextBody, WTableCell)
'Get the index of the cell
Dim index As Integer = cell.GetCellIndex()
'Apply text direction to the next cell
Dim row As WTableRow = cell.OwnerRow
row.RowFormat.BackColor = Color.LightGray
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
WidgetCollection
Gets the body items of the cell.
Declaration
protected override IEntityCollectionBase WidgetCollection { get; }
Property Value
Type |
---|
IEntityCollectionBase |
Overrides
Width
Gets or sets the width(in points) of the cell.
Declaration
public float Width { get; set; }
Property Value
Type | Description |
---|---|
System.Single | The float that specifies the cell width. |
Examples
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;
foreach (WTableRow row in table.Rows)
{
foreach (WTableCell cell in row.Cells)
{
cell.Width = 100;
}
}
//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)
For Each row As WTableRow In table.Rows
For Each cell As WTableCell In row.Cells
cell.Width = 100
Next
Next
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Methods
Clone()
Creates a duplicate copy of the entity.
Declaration
public Entity Clone()
Returns
Type | Description |
---|---|
Entity | The reference to the newly created cell. |
CloneImpl()
Creates a duplicate copy of the entity.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | An System.Object that can be casted as table cell. |
Overrides
CreateLayoutInfo()
Create layout information.
Declaration
protected override void CreateLayoutInfo()
Overrides
GetCellIndex()
Returns the index of the cell in the table row.
Declaration
public int GetCellIndex()
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the cell. |
Examples
The following example illustrates how set get the index of the cell.
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("Cell"));
WTextRange text = selection.GetAsOneRange();
//Get the owner paragraph
WParagraph paragraph = text.OwnerParagraph;
//Get the owner cell
WTableCell cell = paragraph.OwnerTextBody as WTableCell;
//Get the index of the cell
int index = cell.GetCellIndex();
//Apply text direction to the next cell
cell = cell.OwnerRow.Cells[index + 1];
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)
'Find the text in the table
Dim selection As TextSelection = table.Find(New Regex("Cell"))
Dim text As WTextRange = selection.GetAsOneRange()
'Get the owner paragraph
Dim paragraph As WParagraph = text.OwnerParagraph
'Get the owner cell
Dim cell As WTableCell = TryCast(paragraph.OwnerTextBody, WTableCell)
'Get the index of the cell
Dim index As Integer = cell.GetCellIndex()
'Apply text direction to the next cell
cell = cell.OwnerRow.Cells(index + 1)
cell.CellFormat.TextDirection = Syncfusion.DocIO.DLS.TextDirection.Vertical
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()
Overrides
ReadXmlAttributes(IXDLSAttributeReader)
Reads object data from xml attributes.
Declaration
protected override void ReadXmlAttributes(IXDLSAttributeReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeReader | reader | The IXDLSAttributeReader object. |
Overrides
WriteXmlAttributes(IXDLSAttributeWriter)
Writes object data as xml attributes.
Declaration
protected override void WriteXmlAttributes(IXDLSAttributeWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSAttributeWriter | writer | The IXDLSAttributeWriter object. |