- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个程序,该程序将基于文本文件创建文档,到目前为止,它运行良好。我决定这样做,以便更容易地使用图像和其他在 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], style_type)
File "C:\Users\bgrif\AppData\Local\Programs\Python\Python37-32\lib\site-packages\docx\styles\styles.py", line 53, in __getitem__
raise KeyError("no style with name '%s'" % key)
KeyError: "no style with name 'Title'"
有人知道如何解决这个问题吗?提前致谢。
最佳答案
编辑 template.docx
文件以添加 Title
样式:
标题
。在 Word 中,样式库和选择列表中出现大量预定义的段落样式。这些样式的属性对于 Word 应用程序来说是已知的,但在首次使用这些样式之前,Word 实际上并不将任何这些样式存储在文档中。之后,即使没有任何内容使用,它们也会保留在该文档中。
python-docx
只能使用文档中定义的样式,因此您需要将该样式添加到模板文档中才能使用它, .add_heading(.., 0)
调用即可。
关于Python-docx 无法使用现有文档 - 没有名称为 'Title' 的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54945258/
有谁知道如何实现称为 PRUNING 的图像处理技术?任何想法,例子等?我正在使用 OpenCV 和 C#,如果有人可以提供帮助,我将不胜感激。 最佳答案 我假设您希望从图像中移除不需要的杂散和伪影。
假设我已经构建了一个可调用对象数组 callables = [] callables << block1 callables << block2 callables << block3 callabl
这个问题在这里已经有了答案: std::shared_ptr of this (2 个答案) 关闭 8 年前。 我正在学习 C++11 特性,特别是 shared_ptr,我在引用 this 并将其
我主要是一个oracle新手,所以如果这是一个愚蠢的问题,请原谅我...... 我已经阅读了很多关于 authID 的文章,我的理解是 AUTHID 子句指示 Oracle 是否以调用者的权限 (CU
我使用的是 Python 2.7。 按照惯例,__iter__、__init__、__str__ 等内置方法使用双下划线来标识它们。为什么 next() 函数没有这个? 它与这里的其他内置函数一起
这是疏忽吗?还是跟JVM有关? 最佳答案 Java 确实有指针——不能在指针上执行指针运算。 来自可敬的JLS : There are two kinds of types in the Java p
我越来越多地发现宣传“原生”桌面应用程序的服务,但在下载或研究后发现它们是在 Electron 或类似的 Web View 框架中构建的 Web View 。他们误解了“本地人”还是我? 另外,我可以
我尝试在 Wordpress 中使用,但它在控制台中显示 jstree 不是函数在 header PHP 文件中: /dist/libs/jquery.js"> /dist/themes/defaul
我想让 scons 调用带有目录列表的 nosetests。执行此操作的最佳方法是什么? 最佳答案 如果您需要分析外部应用程序的返回码(例如,如果您调用测试),您需要使用 Command() + py
这是一些尝试使用 OOB(紧急)数据的基本代码。我的问题是,如果客户端使用 C 或 Java,则服务器部分的行为不同。请注意,您可能认为这两个客户端都有些棘手,但如果我使用 C 服务器(以更好地控制
虚拟文件系统 (VFS) 或虚拟文件系统交换机是更具体文件系统之上的抽象层。 VFS的目的是允许客户端应用程序以统一的方式访问不同类型的具体文件系统。 如果我们看到 VFS 的实际工作,这个定义似乎是
"Effective Go"状态: By convention, one-method interfaces are named by the method name plus an -er suff
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 3 个月前。 社区审核了是否
在深入研究 Scala 时,我遇到了 这个词。类型类 . 它一直令人困惑,因为一个类是一个类型,而一个类型可以 在 Scala 中是一个类,“类型”和“类”本身就是抽象术语。 在阅读了一些示例后,我感
我正在尝试编写一个简单地杀死我的程序的函数。它被称为退出聊天。但是,当我调用函数 messenger:quitChat() 时,出现此错误。 ** exception error: bad argum
我正在尝试编写一个简单地杀死我的程序的函数。它被称为退出聊天。但是,当我调用函数 messenger:quitChat() 时,出现此错误。 ** exception error: bad argum
如果您向 DB2/zOS 引擎 DBA 询问有关 DB2 行为的问题,DBA 会将 DB2 引擎称为“他”,就像水手使用“她”来指代他的船一样。 例如:“一旦您填充了可用空间,DB2 仍希望在表空间中
案例:我有 2 个具有以下 OneToMany 关系的表:TagAbstract 1..* TagConf,其中: tag_abstract_ID 是一个字段,用于标识许多 TagConf 记录,这些
我有一个表格,我想让第一行“自动固定”(这意味着当向下滚动时它固定在顶部,而如果不向下滚动,它就不固定)。这是代码:``` table { background: yellow; } td
其他动词对我来说都有意义,但我对“发布”作为动词没有太多上下文。它是像在邮局发帖(这有一定道理,虽然看起来有点牵强)还是像在公告板上发帖(对我来说意义不大)?有谁知道是谁决定了“POST”以及为什么选
我是一名优秀的程序员,十分优秀!