Class WTextRange
Represents the text in the Word document. Each part of text can have separate formatting.
Inheritance
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class WTextRange : ParagraphItem, IXDLSSerializable, IOfficeRun, IWTextRange, IParagraphItem, IEntity, IStringWidget, ISplitLeafWidget, ILeafWidget, IWidget, ITextMeasurable
Examples
The following example illustrates how to add a text to the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
//Add new section to the document
IWSection section = document.AddSection();
//Add new paragraph to the section
IWParagraph paragraph = section.AddParagraph();
//Initialize new text range instance
IWTextRange textrange = new WTextRange(document);
//Add text and its formatting
textrange.Text = "A new text is added";
textrange.CharacterFormat.FontSize = 14;
textrange.CharacterFormat.Bold = true;
textrange.CharacterFormat.TextColor = Color.Green;
//Add text range to the paragraph
paragraph.Items.Add(textrange);
//Save the Word document
document.Save("Sample.docx", FormatType.Docx);
//Close the document
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument()
'Add new section to the document
Dim section As IWSection = document.AddSection()
'Add new paragraph to the section
Dim paragraph As IWParagraph = section.AddParagraph()
'Initialize new text range instance
Dim textrange As IWTextRange = New WTextRange(document)
'Add text and its formatting
textrange.Text = "A new text is added"
text.CharacterFormat.FontSize = 14
text.CharacterFormat.Bold = True
text.CharacterFormat.TextColor = Color.Green
'Add text range to the paragraph
paragraph.Items.Add(textrange)
'Save the Word document
document.Save("Sample.docx", FormatType.Docx)
'Close the document
document.Close()
End Sub
Constructors
WTextRange(IWordDocument)
Initializes a new instance of the WTextRange class with the specified IWordDocument instance.
Declaration
public WTextRange(IWordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The IWordDocument instance. |
Properties
CharacterFormat
Gets the character format(font properties) of the text. Read-only.
Declaration
public WCharacterFormat CharacterFormat { get; }
Property Value
Type | Description |
---|---|
WCharacterFormat |
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
Text
Gets or sets the text.
Declaration
public virtual string Text { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
ApplyCharacterFormat(WCharacterFormat)
Applies the specified character format to the text.
Declaration
public void ApplyCharacterFormat(WCharacterFormat charFormat)
Parameters
Type | Name | Description |
---|---|---|
WCharacterFormat | charFormat | The WCharacterFormat to be applied to the text. |
Examples
The following example illustrates how to add a text to the document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument();
document.EnsureMinimal();
//Add new text
IWTextRange text = document.LastParagraph.AppendText("Hello world");
//Initialize character format
WCharacterFormat characterformat = new WCharacterFormat(document);
characterformat.Bold = true;
characterformat.Italic = true;
characterformat.TextColor = Color.Blue;
//Apply character format
text.ApplyCharacterFormat(characterformat);
//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()
document.EnsureMinimal()
'Add new text
Dim text As IWTextRange = document.LastParagraph.AppendText("Hello world")
'Initialize character format
Dim characterformat As New WCharacterFormat(document)
characterformat.Bold = True
characterformat.Italic = True
characterformat.TextColor = Color.Blue
'Apply character format
text.ApplyCharacterFormat(characterformat)
'Save and close the document
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
CloneImpl()
Creates a duplicate copy of the text.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | The reference to the newly created WTextRange instance. |
Overrides
CreateLayoutInfo()
Creates layout information.
Declaration
protected override void CreateLayoutInfo()
Overrides
InitXDLSHolder()
Registers child objects in XDSL holder.
Declaration
protected override void InitXDLSHolder()
Overrides
ReadXmlContent(IXDLSContentReader)
Reads object data from xml attributes.
Declaration
protected override bool ReadXmlContent(IXDLSContentReader reader)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentReader | reader | The IXDLSContentReader object. |
Returns
Type | Description |
---|---|
System.Boolean | The value indicating the presence of xml content. |
Overrides
WriteXmlContent(IXDLSContentWriter)
Writes object data as inside xml element.
Declaration
protected override void WriteXmlContent(IXDLSContentWriter writer)
Parameters
Type | Name | Description |
---|---|---|
IXDLSContentWriter | writer | The IXDLSContentWriter object. |