【问题标题】:pandoc convert html with style sheet to docxpandoc 将带有样式表的 html 转换为 docx
【发布时间】:2015-06-11 13:06:54
【问题描述】:

几个小时以来我一直在努力解决这个问题,我确信解决方案非常简单,或者根本不存在。

我正在尝试将 html 文件转换为 docx!

<!DOCTYPE html>
<html>
<head>
<style>
body {
    background-color: #d0e4fe;
}

h1 {
    color: orange;
    text-align: center;
}

p {
    font-family: "Times New Roman";
    font-size: 20px;
}
</style>
</head>
<body>

<h1>My First CSS Example</h1>
<p>This is a paragraph.</p>

</body>
</html>

我可以转换它没问题,但我无法让样式保持不变。

pandoc -s myfile.html -o test64.docx
pandoc -s -c myfile.css myfile.html -o test64.docx

请救救我。

【问题讨论】:

    标签: html converter docx pandoc


    【解决方案1】:

    以上答案不再有效。根据文档,您现在使用以下方法生成模板:

    pandoc --print-default-data-file reference.docx > custom-reference.docx
    

    有关如何使用模板的完整文档,请访问the documentation 并搜索“--reference-doc”

    【讨论】:

      【解决方案2】:

      在您的命令中,“-c myfile.css”仅在您写入 HTML 或 HTML 5 时使用。它是特定于编写器的选项。

      对于 docx 格式,您需要创建一个“.docx”模板。

      首先运行 pandoc -D docx &gt; my_template.docx,然后在 my_template.docx 中编辑样式。

      终于运行pandoc -s myfile.html --template=my_template -o test64.docx

      【讨论】:

      • 我测试了这个解决方案,它不会在简单的 HTML 文件中保留字体颜色。
      • 您能否详细说明您的尝试。
      • @BlackFrog 你找到解决办法了吗?
      • 这行得通吗?从 HTML 转换为 docx 时,还有其他方法可以保留样式吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      相关资源
      最近更新 更多