Tyl*_*ell 4 html python italics python-docx
是否可以使用应用了样式的 python-docx 将 HTML 插入到文档中?我唯一需要做的就是斜体。
例如,如何插入"Today is <i>Saturday</i>."星期六实际上是用斜体插入的?
谢谢!
p = document.add_paragraph()
p.add_run('Today is ')
p.add_run('Saturday').italic = True
p.add_run('.')
Run Code Online (Sandbox Code Playgroud)
该库不理解 html。您必须自己解析文本,将斜体文本与非斜体文本分开,并将其添加到文档中,如上所示。
或者,从您的 html 文档中:
from htmldocx import HtmlToDocx
new_parser = HtmlToDocx()
new_parser.parse_html_file("html_filename", "docx_filename")
#Files extensions not needed, but tolerated
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3903 次 |
| 最近记录: |