本文介绍了使用javascript将HTML转换为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JavaScript将HTML转换为单词(.docx).我正在使用 http://www.jqueryscript.net/other/Export-Html-To-Word-Document-With-Images-Using-jQuery-Word-Export-Plugin.html 插件进行转换.但这只是转换HTML文件中的所有内容.我的意思是,用头标签标记所有元素,即使其中包含一些内容.输出文件看起来像这样

I am trying to convert HTML to word (.docx) by using JavaScript. I am using this http://www.jqueryscript.net/other/Export-Html-To-Word-Document-With-Images-Using-jQuery-Word-Export-Plugin.html plug-in for conversion. But this one is just converting every thing inside the HTML file. i mean with head tag all elements even with some content inside. output file looks like this

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

--NEXT.ITEM-BOUNDARY Content-Type: text/html; charset="utf-8" Content-Location: 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>

帮我了解如何将HTML内容转换为Word.

Help me out how can i convert content of HTML in word.

推荐答案

我不认为这将在所有设备上的Microsoft Word中一致打开.我实际上一直在进行类似的项目 googoose .它也意味着将html转换为word文档.这在我的台式机和手机版本的Microsoft Word上都对我有用.

I don't believe this will open in Microsoft Word consistently on all devices. I've actually been working on a similar project googoose. It is meant to convert html to word documents as well. This does work for me on both my desktop and mobile phone version of Microsoft Word.

根据我的测试,Word的MIME标头会出现问题,并且还存在没有html,body标签等的事实.

From my testing, Word will have problems with MIME header, and also the fact that there are no html, body tags, etc.

如果您仍在尝试执行此操作,则应调查该项目.它应该得到一段时间的支持,因为还有一个 Wordpress插件使用googoose的链接,该链接在自述文件上.默认操作是在页面加载时下载文档,但是您可以将其设置为在onClick上运行.例如,

You should look into this project if you're still trying to do this. It should be supported for some time, as there's also a Wordpress Plugin that uses googoose, which is linked to on the readme. The default action is to download the document on page load, but you can set it to be run onClick. For example,

只需包含jquery和此插件即可.

Just include jquery and this plugin.

<script type="text/javascript" src="http://github.com/aadel112/googoose/jquery.googoose.js"></script>

然后调用onClick

Then to invoke onClick

jQuery(document).ready(function($) {
        $("a.word-export").click(function(event) {
            $(document).googoose({
                 area: '#export-content'
            });
        });
    });

使用googoose,您可以包括目录,页眉,页脚,自动页码等.您可以在打印"视图中打开文档,设置页边距和页面大小.它比引用的脚本更具可配置性,而该脚本根本不可配置.

With googoose you can include a table of contents, header, footer, automatic page numbering, etc. You can open the document up in Print view, set the margins, and page size. It's way more configurable than the referenced script, which is not configurable at all.

这篇关于使用javascript将HTML转换为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 09:54
查看更多