使用 Docx.js 在 JavaScript 中生成 Word 文档? [英] Generate a Word document in JavaScript with Docx.js?
问题描述
我正在尝试使用 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 行以修复'textAlign' 未定义错误"后,我将原始代码复制到 Google Chrome 控制台中
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>
进入记事本++并将其保存为扩展名为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?
推荐答案
由于对本地文件(blank
文件夹中的所有内容)的 ajaxCalls,此代码无法在 JSFiddle 上运行,或者您应该以 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 blank
folder), 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屋!