Class TextBodyPart
Represents the part of the text body items.
Inheritance
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Portable.dll
Syntax
public class TextBodyPart : Object
Examples
WordDocument document = new WordDocument("Bookmarks.docx", FormatType.Docx);
//Create the bookmark navigator instance to access the bookmark
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
//Move the virtual cursor to the before the end location of the bookmark "Northwind"
bookmarkNavigator.MoveToBookmark("Northwind");
//Get the bookmark content as a text body part.
TextBodyPart part = bookmarkNavigator.GetBookmarkContent();
//Convert the textbody part as a separate Word document.
WordDocument new_document = part.GetAsWordDocument();
//Save and close the document
new_document.Save("Sample.docx", FormatType.Docx);
document.Close();
Dim document As New WordDocument("Bookmarks.docx", FormatType.Docx)
'Create the bookmark navigator instance to access the bookmark
Dim bookmarkNavigator As New BookmarksNavigator(document)
'Move the virtual cursor to the before the end location of the bookmark "Northwind"
bookmarkNavigator.MoveToBookmark("Northwind")
'Get the bookmark content as a text body part.
Dim part As TextBodyPart = bookmarkNavigator.GetBookmarkContent()
'Convert the textbody part as a separate Word document.
Dim new_document As WordDocument = part.GetAsWordDocument()
'Save and close the document
new_document.Save("Sample.docx", FormatType.Docx)
document.Close()
Constructors
TextBodyPart()
Initializes a new instance of the TextBodyPart class.
Declaration
public TextBodyPart()
TextBodyPart(TextBodySelection)
Initializes a new instance of the TextBodyPart class with the specified TextBodySelection.
Declaration
public TextBodyPart(TextBodySelection textBodySelection)
Parameters
Type | Name | Description |
---|---|---|
TextBodySelection | textBodySelection | The TextBodySelection instance. |
TextBodyPart(TextSelection)
Initializes a new instance of the TextBodyPart class with the specified TextSelection.
Declaration
public TextBodyPart(TextSelection textSelection)
Parameters
Type | Name | Description |
---|---|---|
TextSelection | textSelection | The TextSelection instance. |
TextBodyPart(WordDocument)
Initializes a new instance of the TextBodyPart class with the specified WordDocument.
Declaration
public TextBodyPart(WordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
WordDocument | doc | The WordDocument instance. |
Properties
BodyItems
Gets the collection text body items. Read-only.
Declaration
public BodyItemCollection BodyItems { get; }
Property Value
Type | Description |
---|---|
BodyItemCollection | The BodyItemCollection instance. |
Methods
Clear()
Clears the text body items.
Declaration
public void Clear()
Close()
Clears all the contents of the text body part.
Declaration
public void Close()
Copy(ParagraphItem, Boolean)
Copies the specified ParagraphItem and adds the item in a new paragraph to the current WTextBody.
Declaration
public void Copy(ParagraphItem pItem, bool clone)
Parameters
Type | Name | Description |
---|---|---|
ParagraphItem | pItem | The ParagraphItem to be copied. |
System.Boolean | clone | True if to clone and add the item; otherwise, false. |
Copy(TextBodyItem, Boolean)
Copies the specified TextBodyItem and adds it to the current WTextBody.
Declaration
public void Copy(TextBodyItem bodyItem, bool clone)
Parameters
Type | Name | Description |
---|---|---|
TextBodyItem | bodyItem | The TextBodyItem to copy the contents. |
System.Boolean | clone | True if to clone and add the item; otherwise, false. |
Copy(TextBodySelection)
Copies the text from the specified TextBodySelection and adds the text to the current WTextBody.
Declaration
public void Copy(TextBodySelection textSel)
Parameters
Type | Name | Description |
---|---|---|
TextBodySelection | textSel | The TextBodySelection to copy the text. |
Copy(TextSelection)
Copies the text from the specified TextSelection and adds the text as new paragraph in the document.
Declaration
public void Copy(TextSelection textSel)
Parameters
Type | Name | Description |
---|---|---|
TextSelection | textSel | The TextSelection to copy the text. |
GetAsWordDocument()
Returns the content of the text body part as a new Word document.
Declaration
public WordDocument GetAsWordDocument()
Returns
Type | Description |
---|---|
WordDocument | The newly created WordDocument instance. |
PasteAfter(ParagraphItem)
Pastes the ParagraphItem after specified paragraph item index.
Declaration
public void PasteAfter(ParagraphItem paragraphItem)
Parameters
Type | Name | Description |
---|---|---|
ParagraphItem | paragraphItem | The ParagraphItem to be pasted. |
PasteAfter(TextBodyItem)
Pastes the TextBodyItem at the index next to it.
Declaration
public void PasteAfter(TextBodyItem bodyItem)
Parameters
Type | Name | Description |
---|---|---|
TextBodyItem | bodyItem | The TextBodyItem which is to be pasted. |
PasteAt(ITextBody, Int32)
Pastes at specified ITextBody at the specified index.
Declaration
public void PasteAt(ITextBody textBody, int itemIndex)
Parameters
Type | Name | Description |
---|---|---|
ITextBody | textBody | The ITextBody to be pasted. |
System.Int32 | itemIndex | The zero-based index to paste the text body. |
PasteAt(ITextBody, Int32, Int32)
Pastes at specified position.
Declaration
public void PasteAt(ITextBody textBody, int itemIndex, int pItemIndex)
Parameters
Type | Name | Description |
---|---|---|
ITextBody | textBody | The text body. |
System.Int32 | itemIndex | Index of the item. |
System.Int32 | pItemIndex | Index of the p item. |
Examples
//Open the template document
WordDocument document = new WordDocument("Bookmarks.docx", FormatType.Docx);
//Create the bookmark navigator instance to access the bookmark
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
//Move the virtual cursor to the before the end location of the bookmark "Northwind"
bookmarkNavigator.MoveToBookmark("Northwind");
//Get the bookmark content as a text body part.
TextBodyPart part = bookmarkNavigator.GetBookmarkContent();
//Paste the content as first item in the second paragraph.
part.PasteAt(document.Sections[0].Body, 1, 0);
//Save and close the document
document.Save("Result.docx", FormatType.Docx);
document.Close();
'Open the template document
Dim document As New WordDocument("Bookmarks.docx", FormatType.Docx)
'Create the bookmark navigator instance to access the bookmark
Dim bookmarkNavigator As New BookmarksNavigator(document)
'Move the virtual cursor to the before the end location of the bookmark "Northwind"
bookmarkNavigator.MoveToBookmark("Northwind")
'Get the bookmark content as a text body part.
Dim part As TextBodyPart = bookmarkNavigator.GetBookmarkContent()
'Paste the content as first item in the second paragraph.
part.PasteAt(document.Sections(0).Body, 1, 0)
'Save and close the document
document.Save("Result.docx", FormatType.Docx)
document.Close()
PasteAtEnd(ITextBody)
Pastes at end of textbody.
Declaration
public void PasteAtEnd(ITextBody textBody)
Parameters
Type | Name | Description |
---|---|---|
ITextBody | textBody | The text body. |