【发布时间】:2020-06-15 23:52:03
【问题描述】:
我设置了一个 python38 脚本,它读取一个模板 docx 文件,其中样式设置为段落,然后用我建立的新字符串替换文本。但是我现在需要在段落中用斜体字写一些单词,并且我试图避免为了以不同的方式构建段落而进行大量重写。 所以我希望有另一种方式......
是否有我可以使用的特殊字符,MS Word 可以识别并将特定单词变为斜体? 例如,我有以下代码:
for string in instructions.get_instructions()[instruction_key]:
string = string.replace('<number_of_items>',str(no_of_items))
string = string.replace('<item_name>', str(item_ref))
string = string.replace('<front_end>', front_end_ref_formatted)
string = string.replace('<back_end>', back_end_ref_formatted)
string = string.replace('<address>',address)
document.add_paragraph(string, style=style('SOW_Document_install_new_item'))
有没有类似的
for string in instructions.get_instructions()[instruction_key]:
string = string.replace('<<item_name> italics=True>', str(item_ref))
document.add_paragraph(string, style=style('SOW_Document_install_new_item'))
MS Word 会在哪里看到文本中的斜体为 True?类似于'\n' 表示文本文件中的下一行?
【问题讨论】: