ParagraphCollection
Contents
[
Hide
]ParagraphCollection class
Provides typed access to a collection of Paragraph
nodes.
To learn more, visit the Working with Paragraphs documentation article.
public class ParagraphCollection : NodeCollection
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of nodes in the collection. |
Item { get; } | Retrieves a Paragraph at the given index. (2 indexers) |
Methods
Name | Description |
---|---|
Add(Node) | Adds a node to the end of the collection. |
Clear() | Removes all nodes from this collection and from the document. |
Contains(Node) | Determines whether a node is in the collection. |
GetEnumerator() | Provides a simple “foreach” style iteration over the collection of nodes. |
IndexOf(Node) | Returns the zero-based index of the specified node. |
Insert(int, Node) | Inserts a node into the collection at the specified index. |
Remove(Node) | Removes the node from the collection and from the document. |
RemoveAt(int) | Removes the node at the specified index from the collection and from the document. |
ToArray() | Copies all paragraphs from the collection to a new array of paragraphs. (2 methods) |
Examples
Shows how to check whether a paragraph is a move revision.
Document doc = new Document(MyDir + "Revisions.docx");
// This document contains "Move" revisions, which appear when we highlight text with the cursor,
// and then drag it to move it to another location
// while tracking revisions in Microsoft Word via "Review" -> "Track changes".
Assert.AreEqual(6, doc.Revisions.Count(r => r.RevisionType == RevisionType.Moving));
ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs;
// Move revisions consist of pairs of "Move from", and "Move to" revisions.
// These revisions are potential changes to the document that we can either accept or reject.
// Before we accept/reject a move revision, the document
// must keep track of both the departure and arrival destinations of the text.
// The second and the fourth paragraph define one such revision, and thus both have the same contents.
Assert.AreEqual(paragraphs[1].GetText(), paragraphs[3].GetText());
// The "Move from" revision is the paragraph where we dragged the text from.
// If we accept the revision, this paragraph will disappear,
// and the other will remain and no longer be a revision.
Assert.True(paragraphs[1].IsMoveFromRevision);
// The "Move to" revision is the paragraph where we dragged the text to.
// If we reject the revision, this paragraph instead will disappear, and the other will remain.
Assert.True(paragraphs[3].IsMoveToRevision);
See Also
- class NodeCollection
- namespace Aspose.Words
- assembly Aspose.Words