使用Docx.js在JavaScript中生成Word文档? [英] Generate a Word document in JavaScript with Docx.js?

查看:3889
本文介绍了使用Docx.js在JavaScript中生成Word文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 docx.js 生成一个Word文档,但我似乎无法让它工作。

I am trying to use docx.js to generate a Word document but I can't seem to get it to work.

我在修改第247行修复后将原始代码复制到谷歌Chrome控制台'textAlign'未定义错误

I copied the raw code into the Google Chrome console after amending line 247 to fix a "'textAlign' undefined error"

if (inNode.style && inNode.style.textAlign){..}

这使得函数 convertContent 可用。结果是一个对象,例如

Which makes the function convertContent available. The result of which is an Object e.g.

JSON.stringify( convertContent($('<p>Word!</p>)[0]) )

结果 -

"{"string":
      "<w:body>
            <w:p>
                <w:r>
                    <w:t xml:space=\"preserve\">Word!</w:t>
                </w:r>
            </w:p>
       </w:body>"
 ,"charSpaceCount":5
 ,"charCount":5,
 "pCount":1}"

我复制了

<w:body>
    <w:p>
        <w:r>
            <w:t xml:space="preserve">Word!</w:t>
        </w:r>
    </w:p>
</w:body>

进入Notepad ++并将其保存为扩展名为docx的文件但是当我打开它时MS Word,但它说'因为内容有问题而无法打开'。

into Notepad++ and saved it as a file with an extension of 'docx' but when I open it in MS Word but it says 'cannot be opened because there is a problem with the contents'.

我是否遗漏了某些属性或XML标签?

Am I missing some attribute or XML tags or something?

推荐答案

由于ajaxCalls到本地文件(空白中的所有内容),此代码无法在JSFiddle上运行/ code>文件夹),或者您应该以ByteArray格式输入所有文件并使用 jsFiddle echo API: http://doc.jsfiddle.net/use/echo.html

This code can't work on a JSFiddle because of the ajaxCalls to local files (everything that is in the blankfolder), or you should enter all files in ByteArray format and use the jsFiddle echo API: http://doc.jsfiddle.net/use/echo.html

这篇关于使用Docx.js在JavaScript中生成Word文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆