【问题标题】:convert html to docx without losing styles在不丢失样式的情况下将 html 转换为 docx
【发布时间】:2019-10-30 03:32:40
【问题描述】:

我正在尝试将 html 文件转换为 docx 我尝试了 pandoc,但它似乎无法添加样式,所以有什么方法可以将其转换为带有样式的 docx?
编辑:我使用 pygments 突出显示一些代码并希望在 docx 文件中获取它,但似乎 pygments 不支持 docx 输出格式,所以我得到了 html 的输出

【问题讨论】:

    标签: python html docx pandoc pygments


    【解决方案1】:

    没有。来自the pandoc MANUAL

    由于 pandoc 对文档的中间表示不如它在其之间转换的许多格式具有表现力,因此不应期望每种格式之间都能完美转换。 Pandoc 尝试保留文档的结构元素,但不保留诸如边距大小之类的格式细节。

    但是,您可以使用 --reference-doc optioncustom styles 来设置 docx 输出的样式。

    【讨论】:

    • 是的,pandoc 似乎做不到 --reference-doc 选项也需要我没有的 docx 文件,所以看来我正在寻找另一个工具或 python 模块来做它..
    【解决方案2】:

    您可以使用 python-docx 将整个 html 文档嵌入为 altChunk。

    How to add w:altChunk and its relationship with python-docx

    【讨论】:

    • 我希望我能早点找到这个答案,因为我的标签和样式数量非常有限,所以我很难做到..
    猜你喜欢
    • 1970-01-01
    • 2020-08-01
    • 2011-11-20
    • 2012-04-14
    • 2015-01-10
    • 2013-11-21
    • 2018-11-08
    • 2011-01-14
    • 2011-08-02
    相关资源
    最近更新 更多