python-docx style_id 创建word文档时出错
python-docx style_id error while creating a word document
我正在按照 python-docx 网站上提供的教程创建 MS-Word 文档,但出现错误:
M:\Sites>python word.py
C:\Program Files\IBM\SPSS\Statistics\Python\lib\site-packages\docx\styles\sty
les.py:54: UserWarning: style lookup by style_id is deprecated. Use style name a
s key instead.
warn(msg, UserWarning)
word.py
from docx import Document
from docx.shared import Inches
import json
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True
document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='IntenseQuote')
document.add_paragraph(
'first item in unordered list', style='ListBullet'
)
document.add_paragraph(
'first item in ordered list', style='ListNumber'
)
document.add_page_break()
document.save('demo.docx')
简单但难以调试。只需在样式中的单词之间添加 space。
document.add_paragraph('Intense quote', style='IntenseQuote')
更改为:
document.add_paragraph('Intense quote', style='Intense Quote')
我正在按照 python-docx 网站上提供的教程创建 MS-Word 文档,但出现错误:
M:\Sites>python word.py
C:\Program Files\IBM\SPSS\Statistics\Python\lib\site-packages\docx\styles\sty
les.py:54: UserWarning: style lookup by style_id is deprecated. Use style name a
s key instead.
warn(msg, UserWarning)
word.py
from docx import Document
from docx.shared import Inches
import json
document = Document()
document.add_heading('Document Title', 0)
p = document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True
document.add_heading('Heading, level 1', level=1)
document.add_paragraph('Intense quote', style='IntenseQuote')
document.add_paragraph(
'first item in unordered list', style='ListBullet'
)
document.add_paragraph(
'first item in ordered list', style='ListNumber'
)
document.add_page_break()
document.save('demo.docx')
简单但难以调试。只需在样式中的单词之间添加 space。
document.add_paragraph('Intense quote', style='IntenseQuote')
更改为:
document.add_paragraph('Intense quote', style='Intense Quote')