MS Word 是否知道 docx 有一个特殊字符来使单词变为斜体(使用 python-docx)
Is there a special character for docx that MS Word knows to make a word italics (using python-docx)
我设置了一个 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'
表示文本文件中的下一行?
根据 python-docx user guide,斜体应用于 运行 级别。一个段落中的所有文本都包含在一个或多个 运行 的序列中。因此,您似乎需要将 运行 替换为序列 运行s,其中要格式化的单词包含它们自己的 运行,然后将斜体应用于运行.
我设置了一个 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'
表示文本文件中的下一行?
根据 python-docx user guide,斜体应用于 运行 级别。一个段落中的所有文本都包含在一个或多个 运行 的序列中。因此,您似乎需要将 运行 替换为序列 运行s,其中要格式化的单词包含它们自己的 运行,然后将斜体应用于运行.