Class WParagraphCollection
Represents a collection of IWParagraph objects.
Implements
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.NET.dll
Syntax
public class WParagraphCollection : EntitySubsetCollection, IWParagraphCollection, IEntityCollectionBase, ICollectionBase, IEnumerable
Examples
private void Button1_Click(System.Object sender, System.EventArgs e)
{
//Create a new Word document
WordDocument document = new WordDocument("Template.docx");
//Find the specified text from the document
TextSelection selection = document.Find("paragraph", false, false);
WTextRange range = selection.GetAsOneRange();
//Get its owner paragraph
WParagraph paragraph = range.OwnerParagraph;
WTextBody textbody = paragraph.OwnerTextBody;
//Get the collection of paragraphs in the section
WParagraphCollection collection = (WParagraphCollection)textbody.Paragraphs;
//Get the index of the paragraph
int index = collection.IndexOf(range.OwnerParagraph);
paragraph = new WParagraph(document);
paragraph.AppendText("hello world");
//Insert new item
collection.Insert(index + 1, paragraph);
//Removes paragraph at index zero
collection.RemoveAt(0);
//Save and close the paragraph.
document.Save("Result.docx");
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
'Create a new Word document
Dim document As New WordDocument("Template.docx")
'Find the specified text from the document
Dim selection As TextSelection = document.Find("paragraph", False, False)
Dim range As WTextRange = selection.GetAsOneRange()
'Get its owner paragraph
Dim paragraph As WParagraph = range.OwnerParagraph
Dim textbody As WTextBody = paragraph.OwnerTextBody
'Get the collection of paragraphs in the section
Dim collection As WParagraphCollection = DirectCast(textbody.Paragraphs, WParagraphCollection)
'Get the index of the paragraph
Dim index As Integer = collection.IndexOf(range.OwnerParagraph)
paragraph = New WParagraph(document)
paragraph.AppendText("hello world")
'Insert new item
collection.Insert(index - 1, paragraph)
'Removes paragraph at index zero
collection.RemoveAt(0)
'Save and close the paragraph.
document.Save("Result.docx")
document.Close()
End Sub
Constructors
WParagraphCollection(BodyItemCollection)
Initializes a new instance of the WParagraphCollection class with the specified collection of text body items.
Declaration
public WParagraphCollection(BodyItemCollection bodyItems)
Parameters
Type | Name | Description |
---|---|---|
BodyItemCollection | bodyItems | The collection of text body items. |
Properties
Item[Int32]
Gets the WParagraph at the specified index.
Declaration
public WParagraph this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The zero-based index of the paragraph to get from the collection. |
Property Value
Type | Description |
---|---|
WParagraph | The WParagraph instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | The index is not valid in the WParagraphCollection. |
Methods
Add(IWParagraph)
Adds a paragraph to the collection.
Declaration
public int Add(IWParagraph paragraph)
Parameters
Type | Name | Description |
---|---|---|
IWParagraph | paragraph | The paragraph to be added. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the added paragraph. |
Contains(IWParagraph)
Determines whether the WParagraphCollection contains a specified paragraph.
Declaration
public bool Contains(IWParagraph paragraph)
Parameters
Type | Name | Description |
---|---|---|
IWParagraph | paragraph | The paragraph to be found. |
Returns
Type | Description |
---|---|
System.Boolean | True if paragraph is found; otherwise, false. |
IndexOf(IWParagraph)
Returns the zero-based index of the specified paragraph.
Declaration
public int IndexOf(IWParagraph paragraph)
Parameters
Type | Name | Description |
---|---|---|
IWParagraph | paragraph | The paragraph to which the index to be found. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based index of the paragraph. |
Insert(Int32, IWParagraph)
Inserts the specified paragraph into collection at the specified index.
Declaration
public void Insert(int index, IWParagraph paragraph)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The integer that specifies the index. |
IWParagraph | paragraph | The paragraph to be inserted. |
Remove(IWParagraph)
Removes the specified paragraph from the collection.
Declaration
public void Remove(IWParagraph paragraph)
Parameters
Type | Name | Description |
---|---|---|
IWParagraph | paragraph | The paragraph to be removed from the collection. |
RemoveAt(Int32)
Removes the paragraph at the specified index from the collection.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index of the paragraph to be removed. |