Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript将HTML转换为单词_Javascript_Jquery_Html_Fileserver - Fatal编程技术网

使用javascript将HTML转换为单词

使用javascript将HTML转换为单词,javascript,jquery,html,fileserver,Javascript,Jquery,Html,Fileserver,我正在尝试使用JavaScript将HTML转换为word(.docx)。我正在使用此插件进行转换。但这只是转换HTML文件中的所有内容。我的意思是用头标记所有元素,即使里面有一些内容。输出文件如下所示 Mime版本:1.0内容库: file:///home/userprofile/JsWs/sample.html 内容类型: 多部分/相关;boundary=“NEXT.ITEM-boundary”;type=“text/html” --NEXT.ITEM-BOUNDARY内容类型:text/h

我正在尝试使用JavaScript将HTML转换为word(.docx)。我正在使用此插件进行转换。但这只是转换HTML文件中的所有内容。我的意思是用头标记所有元素,即使里面有一些内容。输出文件如下所示

Mime版本:1.0内容库: file:///home/userprofile/JsWs/sample.html 内容类型: 多部分/相关;boundary=“NEXT.ITEM-boundary”;type=“text/html”

--NEXT.ITEM-BOUNDARY内容类型:text/html;charset=“utf-8”内容位置:file:///home/userprofile/JsWs/sample.html

  <p>this is going to be paragraph </p>

  </body></html>
这将是一段

--下一步:项目边界--

而且我的html是

<html> 
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="FileSaver.js"></script>
        <script src="jquery.wordexport.js"></script>
    </head>
    <body>
        <script type="text/javascript">
        jQuery(document).ready(function($) {
            $("a.word-export").click(function(event) {
                $("#export-content").wordExport();
            });
        });
        </script>
        <div id="export-content">

        <p>this is going to be paragraph </p>

        </div>

        <a class="word-export" href="javascript:void(0)"> Export as .doc </a>
    </body>
</html>

jQuery(文档).ready(函数($){
$(“a.word-export”)。单击(函数(事件){
$(“#导出内容”).wordExport();
});
});
这将是一段


请帮助我如何在word中转换HTML内容。

我不相信这会在所有设备上在Microsoft word中持续打开。我实际上一直在做一个类似的项目。它还可以将html转换为word文档。这对我的桌面版和手机版的MicrosoftWord都适用

根据我的测试,Word在MIME头上会有问题,而且没有html、body标记等

如果你还在努力的话,你应该调查这个项目。它应该被支持一段时间,因为还有一个使用googoose的,在自述中链接到的。默认操作是在页面加载时下载文档,但您可以将其设置为在单击时运行。比如说,

只需包括jquery和这个插件

<script type="text/javascript" src="http://github.com/aadel112/googoose/jquery.googoose.js"></script>
使用googoose,您可以包括目录、页眉、页脚、自动页码等。您可以在打印视图中打开文档,设置页边距和页面大小。它比引用的脚本更具可配置性,而引用的脚本根本不可配置。

试试这个

function ConvertToHtml()
{
    var div = document.createElement("div");
    div.id = "export-content";
    div.innerHTML = "<p>this is going to be paragraph </p>";
    document.body.appendChild(div);
    $("#export-content").wordExport();
}
函数ConvertToHtml()
{
var div=document.createElement(“div”);
div.id=“导出内容”;
div.innerHTML=“这将是段落

”; 文件.正文.附件(div); $(“#导出内容”).wordExport(); }
我建议您使用名为Docverter的Api。它允许您将HTML转换为DOCX。或者使用您刚刚保存的我的一天!非常感谢。@Aaron我们可以在这里使用外部css吗?或者我们只需要内联设置文档样式?@Aaron如何使用您的解决方案将html文本导出为
.docx
function ConvertToHtml()
{
    var div = document.createElement("div");
    div.id = "export-content";
    div.innerHTML = "<p>this is going to be paragraph </p>";
    document.body.appendChild(div);
    $("#export-content").wordExport();
}