MCPcopy Index your code
hub / github.com/python-openxml/python-docx / add_heading

Method add_heading

src/docx/document.py:90–101  ·  view source on GitHub ↗

Return a heading paragraph newly added to the end of the document. The heading paragraph will contain `text` and have its paragraph style determined by `level`. If `level` is 0, the style is set to `Title`. If `level` is 1 (or omitted), `Heading 1` is used. Otherwise the sty

(self, text: str = "", level: int = 1)

Source from the content-addressed store, hash-verified

88 return comment
89
90 def add_heading(self, text: str = "", level: int = 1):
91 """Return a heading paragraph newly added to the end of the document.
92
93 The heading paragraph will contain `text` and have its paragraph style
94 determined by `level`. If `level` is 0, the style is set to `Title`. If `level`
95 is 1 (or omitted), `Heading 1` is used. Otherwise the style is set to `Heading
96 {level}`. Raises |ValueError| if `level` is outside the range 0-9.
97 """
98 if not 0 <= level <= 9:
99 raise ValueError("level must be in range 0-9, got %d" % level)
100 style = "Title" if level == 0 else "Heading %d" % level
101 return self.add_paragraph(text, style)
102
103 def add_page_break(self):
104 """Return newly |Paragraph| object containing only a page break."""

Calls 1

add_paragraphMethod · 0.95