Class TextBodySelection
Represents a selection of part of text body in the Word document.
Inheritance
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Base.dll
Syntax
public class TextBodySelection : Object
Constructors
TextBodySelection(ITextBody, Int32, Int32, Int32, Int32)
Initializes a new instance of the TextBodySelection class with the textbody, start paragraph index, end paragraph index, start paragraph item index, and end paragraph item index.
Declaration
public TextBodySelection(ITextBody textBody, int itemStartIndex, int itemEndIndex, int pItemStartIndex, int pItemEndIndex)
Parameters
Type | Name | Description |
---|---|---|
ITextBody | textBody | The ITextBody instance. |
System.Int32 | itemStartIndex | The integer specifying paragraph starting index. |
System.Int32 | itemEndIndex | The integer specifying paragraph ending index. |
System.Int32 | pItemStartIndex | The integer specifying paragraph item starting index in first paragraph. |
System.Int32 | pItemEndIndex | The integer specifying paragraph item ending index in last paragraph. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Open the template document
WordDocument document = new WordDocument("Template.docx", FormatType.Docx);
//Get the text body of first section
WTextBody textbody = document.Sections[0].Body;
//Selects the items in the text body
TextBodySelection selection = new TextBodySelection(textbody, 0, 1, 0, 1);
//Create new text body part
TextBodyPart textbodyPart = new TextBodyPart(document);
//Copy the selected items
textbodyPart.Copy(selection);
//Paste the selected items.
textbodyPart.PasteAt(textbody, 2);
//Save and close the document.
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Open the template document
Dim document As New WordDocument("Template.docx", FormatType.Docx)
'Get the text body of first section
Dim textbody As WTextBody = document.Sections(0).Body
'Selects the items in the text body
Dim selection As New TextBodySelection(textbody, 0, 1, 0, 1)
'Create new text body part
Dim textbodyPart As New TextBodyPart(document)
'Copy the selected items
textbodyPart.Copy(selection)
'Paste the selected items.
textbodyPart.PasteAt(textbody, 2)
'Save and close the document.
document.Save("Sample.docx")
document.Close()
End Sub
TextBodySelection(ParagraphItem, ParagraphItem)
Initializes a new instance of the TextBodySelection class with start paragraph item and end paragraph item.
Declaration
public TextBodySelection(ParagraphItem itemStart, ParagraphItem itemEnd)
Parameters
Type | Name | Description |
---|---|---|
ParagraphItem | itemStart | The ParagraphItem that specifies the start of the selection. |
ParagraphItem | itemEnd | The ParagraphItem that specifies the end of the selection. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Open the template document
WordDocument document = new WordDocument("Bookmarks.docx", FormatType.Docx);
//Get the text body of first section
WTextBody textbody = document.Sections[0].Body;
//Gets the second paragraph
WParagraph paragraph = textbody.Paragraphs[1];
//Get the start and end items
ParagraphItem startItem = (ParagraphItem)paragraph.ChildEntities[0];
ParagraphItem endItem = (ParagraphItem)paragraph.ChildEntities[1];
//Selects the items in the text body
TextBodySelection selection = new TextBodySelection(startItem, endItem);
//Create new text body part
TextBodyPart textbodyPart = new TextBodyPart(document);
//Copy the selected items
textbodyPart.Copy(selection);
//Paste the selected items.
textbodyPart.PasteAt(textbody, 2);
//Save and close the document.
document.Save("Result.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Open the template document
Dim document As New WordDocument("Bookmarks.docx", FormatType.Docx)
'Get the text body of first section
Dim textbody As WTextBody = document.Sections(0).Body
'Gets the second paragraph
Dim paragraph As WParagraph = textbody.Paragraphs(1)
'Get the start and end items
Dim startItem As ParagraphItem = DirectCast(paragraph.ChildEntities(0), ParagraphItem)
Dim endItem As ParagraphItem = DirectCast(paragraph.ChildEntities(1), ParagraphItem)
'Selects the items in the text body
Dim selection As New TextBodySelection(startItem, endItem)
'Create new text body part
Dim textbodyPart As New TextBodyPart(document)
'Copy the selected items
textbodyPart.Copy(selection)
'Paste the selected items.
textbodyPart.PasteAt(textbody, 2)
'Save and close the document.
document.Save("Result.docx")
document.Close()
End Sub
Properties
ItemEndIndex
Gets or sets the end index of the text body item.
Declaration
public int ItemEndIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The zero-based index of the item. |
ItemStartIndex
Gets or sets the start index of the text body item.
Declaration
public int ItemStartIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The zero-based index of the item. |
ParagraphItemEndIndex
Gets or sets the end index of the paragraph item.
Declaration
public int ParagraphItemEndIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The zero-based index of the item. |
ParagraphItemStartIndex
Gets or sets the start index of the paragraph item.
Declaration
public int ParagraphItemStartIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The zero-based index of the item. |
TextBody
Gets the WTextBody of the selection part. Read-only.
Declaration
public WTextBody TextBody { get; }
Property Value
Type | Description |
---|---|
WTextBody | The WTextBody instance. |