ParagraphCollection class
ParagraphCollection class
Provides typed access to a collection of Paragraph nodes. To learn more, visit the Working with Paragraphs documentation article.
Inheritance: ParagraphCollection → NodeCollection
Indexers
Name | Description |
---|---|
__getitem__(index) | Retrieves a Paragraph at the given index. |
Properties
Name | Description |
---|---|
count | Gets the number of nodes in the collection. (Inherited from NodeCollection) |
Methods
Name | Description |
---|---|
add(node) | Adds a node to the end of the collection. (Inherited from NodeCollection) |
clear() | Removes all nodes from this collection and from the document. (Inherited from NodeCollection) |
contains(node) | Determines whether a node is in the collection. (Inherited from NodeCollection) |
index_of(node) | Returns the zero-based index of the specified node. (Inherited from NodeCollection) |
insert(index, node) | Inserts a node into the collection at the specified index. (Inherited from NodeCollection) |
remove(node) | Removes the node from the collection and from the document. (Inherited from NodeCollection) |
remove_at(index) | Removes the node at the specified index from the collection and from the document. (Inherited from NodeCollection) |
to_array() | Copies all paragraphs from the collection to a new array of paragraphs. |
Examples
Shows how to check whether a paragraph is a move revision.
doc = aw.Document(MY_DIR + '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".
self.assertEqual(6, len([r for r in doc.revisions if r.revision_type == aw.RevisionType.MOVING]))
paragraphs = doc.first_section.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.
self.assertEqual(paragraphs[1].get_text(), paragraphs[3].get_text())
# 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.
self.assertTrue(paragraphs[1].is_move_from_revision)
# 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.
self.assertTrue(paragraphs[3].is_move_to_revision)
See Also
- module aspose.words
- class NodeCollection