我想使用包对我的段落应用样式(列表、列表号、列表号2…等)
python-docx
. 我创建了自己的MS Word模板,其中有一些特定的风格,我做。此外,我有时需要应用MS Word内置风格。这是我的代码:
elif to_U_sc:
to_write = to_U_sc.group(2)
paragraph = self.template.add_paragraph(to_write, style='List')
elif to_O_sc2:
to_write = to_O_sc2.group(2)
paragraph = self.template.add_paragraph(to_write, style='ListNumber')
在这里,
self.template
是
Document
反对。问题是不管我用什么
ListNumber
或
List Number
或
wdStyleListNumber
作为样式名,它们都会引发错误
没有这种风格
. 比如:
File "/usr/lib/python2.7/site-packages/python_docx-0.8.5-py2.7.egg/docx/styles/styles.py", line 57, in __getitem__
raise KeyError("no style with name '%s'" % key)
KeyError: u"no style with name 'ListNumber'"
我尝试使用代码打印模板