to_array method
to_array()
Copies all paragraphs from the collection to a new array of paragraphs.
def to_array(self):
...
Returns
An array of paragraphs.
Examples
Shows how to create an array from a NodeCollection.
doc = aw.Document(file_name=MY_DIR + 'Paragraphs.docx')
paras = list(doc.first_section.body.paragraphs)
self.assertEqual(22, len(paras))
Shows how to use “hot remove” to remove a node during enumeration.
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.writeln('The first paragraph')
builder.writeln('The second paragraph')
builder.writeln('The third paragraph')
builder.writeln('The fourth paragraph')
# Remove a node from the collection in the middle of an enumeration.
for para in list(doc.first_section.body.paragraphs):
if 'third' in para.range.text:
para.remove()
self.assertFalse('The third paragraph' in doc.get_text())
See Also
- module aspose.words
- class ParagraphCollection