我已经设置了一个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会看到斜体在文本中是真实的?类似于'\n'在文本文件中的下一行的意思?
发布于 2020-06-16 10:01:25
根据python用户指南,斜体是在运行级别上应用的。段落中的所有文本都包含在一个或多个运行序列中。因此,您似乎需要用要格式化的单词包含它们自己的运行的序列来替换run,然后将斜体字应用于该运行。
https://stackoverflow.com/questions/62398814
复制相似问题