Interface ITextBody
Represents the text body
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.UWP.dll
Syntax
public interface ITextBody : ICompositeEntity, IEntity
Properties
ChildEntities
Gets the child elements of the WTextBody.
Declaration
EntityCollection ChildEntities { get; }
Property Value
Type | Description |
---|---|
EntityCollection | The collection of the child elements. |
FormFields
Gets the collection of form fields in the WTextBody. Read-only.
Declaration
FormFieldCollection FormFields { get; }
Property Value
Type | Description |
---|---|
FormFieldCollection | The collection that represents the form fields in the text body. |
See Also
LastParagraph
Gets the last paragraph in the section. Read-only.
Declaration
IWParagraph LastParagraph { get; }
Property Value
Type | Description |
---|---|
IWParagraph | The IWParagraph object. |
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Load a template Word document
WordDocument document = new WordDocument("Template.docx");
//Get the textbody of first section
WTextBody textbody = document.Sections[0].Body;
//Get the last paragraph
IWParagraph paragraph = textbody.LastParagraph;
//Set horizontal alignment
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
//Save and close the document
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Load a template Word document
Dim document As New WordDocument("Template.docx")
'Get the textbody of first section
Dim textbody As WTextBody = document.Sections(0).Body
'Get the last paragraph
Dim paragraph As IWParagraph = textbody.LastParagraph
'Set horizontal alignment
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
Paragraphs
Gets the collection of paragraphs in the WTextBody. Read-only.
Declaration
IWParagraphCollection Paragraphs { get; }
Property Value
Type | Description |
---|---|
IWParagraphCollection | The collection that represents the paragraphs in the text body. |
See Also
Tables
Gets the collection of tables in the WTextBody. Read-only.
Declaration
IWTableCollection Tables { get; }
Property Value
Type | Description |
---|---|
IWTableCollection | The collection that represents the tables in the text body. |
See Also
Methods
AddBlockContentControl(ContentControlType)
Declaration
IBlockContentControl AddBlockContentControl(ContentControlType controlType)
Parameters
Type | Name | Description |
---|---|---|
ContentControlType | controlType |
Returns
Type |
---|
IBlockContentControl |
Examples
The following example illustrates how to add a block content control to the text body.
//Create new Word document
WordDocument document = new WordDocument();
//Add new section
IWSection section = document.AddSection();
WTextBody textbody = section.Body;
//Add a block content control to the text body
BlockContentControl blockControl = textbody.AddBlockContentControl(ContentControlType.RichText) as BlockContentControl;
//Add text to the control added
blockControl.TextBody.AddParagraph().AppendText("A new block control is added");
//Save and close the document
document.Save("Sample.docx");
document.Close();
'Create new Word document
Dim document As New WordDocument()
'Add new section
Dim section As IWSection = document.AddSection()
Dim textbody As WTextBody = section.Body
'Add a block content control to the text body
Dim blockControl As BlockContentControl = TryCast(textbody.AddBlockContentControl(ContentControlType.RichText), BlockContentControl)
'Add text to the control added
blockControl.TextBody.AddParagraph().AppendText("A new block control is added")
'Save and close the document
document.Save("Sample.docx")
document.Close()
AddParagraph()
Adds a new paragraph at the end of section.
Declaration
IWParagraph AddParagraph()
Returns
Type | Description |
---|---|
IWParagraph | The reference to the newly added IWParagraph object. |
Examples
The following example illustrates how to add a paragraph to the text body.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create new Word document
WordDocument document = new WordDocument();
//Add new section
IWSection section = document.AddSection();
WTextBody textbody = section.Body;
//Add a paragraph to the text body
WParagraph paragraph = textbody.AddParagraph() as WParagraph;
//Add text
paragraph.AppendText("A new paragraph is added");
//Save and close the document
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create new Word document
Dim document As New WordDocument()
'Add new section
Dim section As IWSection = document.AddSection()
Dim textbody As WTextBody = section.Body
'Add a paragraph to the text body
Dim paragraph As WParagraph = TryCast(textbody.AddParagraph(), WParagraph)
'Add text
paragraph.AppendText("A new paragraph is added")
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
AddTable()
Adds a new table at the end of the section.
Declaration
IWTable AddTable()
Returns
Type | Description |
---|---|
IWTable | The reference to the newly added IWTable object. |
Examples
The following example illustrates how to add a table to the text body.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create new Word document
WordDocument document = new WordDocument();
//Add new section
IWSection section = document.AddSection();
WTextBody textbody = section.Body;
//Add a table to the text body
IWTable table = textbody.AddTable();
table.ResetCells(2, 2);
//Save and close the document
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create new Word document
Dim document As New WordDocument()
'Add new section
Dim section As IWSection = document.AddSection()
Dim textbody As WTextBody = section.Body
'Add a table to the text body
Dim table As IWTable = textbody.AddTable()
table.ResetCells(2, 2)
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
EnsureMinimum()
If the text body has no paragraphs, creates and add one paragraph to the text body.
Declaration
void EnsureMinimum()
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create new Word document
WordDocument document = new WordDocument();
//Add new section
IWSection section = document.AddSection();
WTextBody textbody = section.Body;
//Add one paragraph to the section body
textbody.EnsureMinimum();
textbody.LastParagraph.AppendText("Last paragraph");
//Save and close the document
document.Save("Sample.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create new Word document
Dim document As New WordDocument()
'Add new section
Dim section As IWSection = document.AddSection()
Dim textbody As WTextBody = section.Body
'Add one paragraph to the section body
textbody.EnsureMinimum()
textbody.LastParagraph.AppendText("Last paragraph")
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
InsertXHTML(String)
Declaration
void InsertXHTML(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html |
Examples
The following example illustrates how to insert a html string to the text body.
//Load the template document
WordDocument document = new WordDocument("Template.docx");
//Html string to be inserted
string htmlstring = "This text is inserted as HTML string.
";
//Append Html string as first item of the second paragraph in the document
document.Sections[0].Body.InsertXHTML(htmlstring);
//Save and close the document
document.Save("Sample.docx");
document.Close();
Private Sub button_Click(sender As Object, e As EventArgs)
'Load the template document
Dim document As New WordDocument("Template.docx")
'Html string to be inserted
Dim htmlstring As String = "This text is inserted as HTML string.
"
'Append Html string as first item of the second paragraph in the document
document.Sections(0).Body.InsertXHTML(htmlstring)
'Save and close the document
document.Save("Sample.docx")
document.Close()
End Sub
InsertXHTML(String, Int32)
Declaration
void InsertXHTML(string html, int paragraphIndex)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | |
System.Int32 | paragraphIndex |
Examples
The following example illustrates how to insert a html string at the specified paragraph in the text body.
//Load the template document
WordDocument document = new WordDocument("Template.docx");
//Html string to be inserted
string htmlstring = "This text is inserted as HTML string.
";
//Append Html string as first item of the second paragraph in the document
document.Sections[0].Body.InsertXHTML(htmlstring, 2);
//Save and close the document
document.Save("Sample.docx");
document.Close();
'Load the template document
Dim document As New WordDocument("Template.docx")
'Html string to be inserted
Dim htmlstring As String = "This text is inserted as HTML string.
"
'Append Html string as first item of the second paragraph in the document
document.Sections(0).Body.InsertXHTML(htmlstring, 2)
'Save and close the document
document.Save("Sample.docx")
document.Close()
InsertXHTML(String, Int32, Int32)
Declaration
void InsertXHTML(string html, int paragraphIndex, int paragraphItemIndex)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | |
System.Int32 | paragraphIndex | |
System.Int32 | paragraphItemIndex |