You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've added a Table of Contents (ToC) to my document via Mustash's code in #36
Now I'd like to add a header above it, in the ToC Header style (so that it doesn't add it's own header in the table).
However, I seem to be unable to find the correct style for this in the docs.
from docx.enum.style import WD_BUILTIN_STYLE
document = Document()
document.add_paragraph('Table of Contents', style=WD_BUILTIN_STYLE.INDEX_HEADING)
document.save()
Traceback (most recent call last):
[ . . . ]
File "/root/TOOLS/.../.../libs/export.py", line 330, in export_to_word
document.add_paragraph('Table of Contents', style=WD_BUILTIN_STYLE.INDEX_HEADING)
File "/usr/local/lib/python3.7/dist-packages/docx/document.py", line 63, in add_paragraph
return self._body.add_paragraph(text, style)
File "/usr/local/lib/python3.7/dist-packages/docx/blkcntnr.py", line 38, in add_paragraph
paragraph.style = style
File "/usr/local/lib/python3.7/dist-packages/docx/text/paragraph.py", line 111, in style
style_or_name, WD_STYLE_TYPE.PARAGRAPH
File "/usr/local/lib/python3.7/dist-packages/docx/parts/document.py", line 76, in get_style_id
return self.styles.get_style_id(style_or_name, style_type)
File "/usr/local/lib/python3.7/dist-packages/docx/styles/styles.py", line 113, in get_style_id
return self._get_style_id_from_name(style_or_name, style_type)
File "/usr/local/lib/python3.7/dist-packages/docx/styles/styles.py", line 143, in _get_style_id_from_name
return self._get_style_id_from_style(self[style_name], style_type)
File "/usr/local/lib/python3.7/dist-packages/docx/styles/styles.py", line 57, in __getitem__
raise KeyError("no style with name '%s'" % key)
KeyError: "no style with name 'INDEX_HEADING (-34)'"
The text was updated successfully, but these errors were encountered:
Hi
I've added a Table of Contents (ToC) to my document via Mustash's code in #36
Now I'd like to add a header above it, in the ToC Header style (so that it doesn't add it's own header in the table).
However, I seem to be unable to find the correct style for this in the docs.
The text was updated successfully, but these errors were encountered: