小编Bri*_*con的帖子

Python-docx 无法使用现有文档 - 没有名称为“Title”的样式

我正在尝试制作一个程序,该程序将基于文本文件创建文档,到目前为止,它工作得很好。我决定这样做,以便更容易地使用图像和其他在 Python-docx 中不支持/难以有效使用的东西。在使用完全相同的代码但使用 Doc = document() 时,我使用 Doc = document("template.docx")。修改后,文件保存到不同的docx文件中。我在尝试使用模板时遇到这些错误。创建新文档时没有错误。

回溯(最近一次调用最后一次):

  File "C:\Users\bgrif\Desktop\QPA.py", line 45, in <module>
    Doc.add_heading("QuizPax 28/02/2019",0)
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\document.py", line 39, in add_heading
    return self.add_paragraph(text, style)
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\document.py", line 56, in add_paragraph
    return self._body.add_paragraph(text, style)
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\blkcntnr.py", line 39, in add_paragraph
    paragraph.style = style
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\text\paragraph.py", line 111, in style
    style_or_name, WD_STYLE_TYPE.PARAGRAPH
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\parts\document.py", line 78, in get_style_id
    return self.styles.get_style_id(style_or_name, style_type)
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\styles\styles.py", line 109, in get_style_id
    return self._get_style_id_from_name(style_or_name, style_type)
  File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\styles\styles.py", line 139, in _get_style_id_from_name
    return self._get_style_id_from_style(self[style_name], …
Run Code Online (Sandbox Code Playgroud)

python python-3.x python-docx

2
推荐指数
1
解决办法
4112
查看次数

标签 统计

python ×1

python-3.x ×1

python-docx ×1