clear_content method

clear_content()

Clears the section.

def clear_content(self):
    ...

Remarks

The text of Section.body is cleared, only one empty paragraph is left that represents the section break.

The text of all headers and footers is cleared, but HeaderFooter objects themselves are not removed.

Examples

Shows how to clear the contents of a section.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.write("Hello world!")

self.assertEqual("Hello world!", doc.get_text().strip())
self.assertEqual(1, doc.first_section.body.paragraphs.count)

# Running the "clear_content" method will remove all the section contents
# but leave a blank paragraph to add content again.
doc.first_section.clear_content()

self.assertEqual("", doc.get_text().strip())
self.assertEqual(1, doc.first_section.body.paragraphs.count)

See Also