【问题标题】:How to export html page to ms. word (.doc) with external CSS?如何将html页面导出到ms。带有外部 CSS 的 word (.doc)?
【发布时间】:2022-01-20 02:06:05
【问题描述】:

我想使用外部 CSS 将 html 页面导出为 .doc 格式。 我正在使用jQuery.wordexport.jsFileSaver.js

这是我要导出的内容:

<div id="export">Content</div>

这是js:

<script type="text/javascript">
    jQuery(document).ready(function($) {
        $("a.word-export").click(function(event) {
            $("#export").wordExport();
        });
    });
    </script>

我还包括外部 css:

<link href="css/style.css" rel="stylesheet">

我可以将 html 页面导出为 word,但问题是它不允许我包含外部 CSS。它适用于内联 CSS,但它使代码看起来很乱,我必须在每个页面上键入相同的样式。而且,它不读取边距和填充,所以我无法管理文本的位置。

谁能帮帮我?对此,我真的非常感激。谢谢!

【问题讨论】:

    标签: javascript jquery html css .doc


    【解决方案1】:

    你可以放 css 文件&lt;link href="{Absolute Paths}css/style.css" rel="stylesheet"&gt; 的完整路径(绝对路径),因为 Ms-Word 无法读取相对路径。

    例子:

    &lt;link href="http://www.domain.com/css/style.css" rel="stylesheet"&gt;

    【讨论】:

    • 我把&lt;link href="http://localhost:1337/test/css/style.css" rel="stylesheet"&gt;放在那里(在桌子上,我试图导出表格),我可以在html页面中看到颜色,但它似乎没有出现在毫秒字。
    • 我认为当您导出到 ms-word 时,插件 jQuery.wordexport.js 和 FileSaver.js 出现了问题。此插件不包含任何 css 或 js 文件到 word 文件中。
    • 感谢您的帮助!
    • 嗨@RashimCatalanDhaubanjar 你说它不起作用是什么意思?无法导出还是没有应用css样式?
    • @HerlinaAstari 是的,它有效,我只需要使用 ms-office msdn.microsoft.com/en-us/library/aa338201(v=office.12).aspx 接受的那些 css
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 2013-08-18
    • 2015-03-28
    • 2016-03-28
    • 2013-02-24
    • 1970-01-01
    相关资源
    最近更新 更多