javascript 在 Node.JS 中解析 Microsoft Office 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12902792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse Microsoft Office files in Node.JS
提问by arknave
I'm working on a web application where users can upload Microsoft Office Document files. Right now, our server is running Node.JS with Express.js and we're hosted on Heroku. Because of this, I don't think that I can install programs such as abiword or catdoc. I can handle the file uploads, but can't parse the contents of the document.
我正在开发一个 Web 应用程序,用户可以在其中上传 Microsoft Office 文档文件。现在,我们的服务器运行 Node.JS 和 Express.js,我们托管在 Heroku 上。因此,我认为我无法安装诸如 abiword 或 catdoc 之类的程序。我可以处理文件上传,但无法解析文档的内容。
How can I read the contents of the doc file? The information will then be put into a database. It'd be nice to preserve basic formatting (bold, italic, underline), but not essential.
如何读取 doc 文件的内容?然后将信息放入数据库。保留基本格式(粗体、斜体、下划线)会很好,但不是必需的。
采纳答案by explunit
While there don't seem to be anything you can get with NPM that will do Word directly, you might be able to use a REST API to request it via another cloud service. For example Saaspose(they of the famous Aspose tools) have public API for Word, Excel, PDF, and others. They list node.js, javascript, and Heroku support on their page.
虽然您似乎无法使用 NPM 获得任何可以直接执行 Word 的东西,但您或许可以使用 REST API 通过另一个云服务来请求它。例如Saaspose(它们是著名的 Aspose 工具)具有Word、Excel、PDF等的公共 API 。他们在他们的页面上列出了 node.js、javascript 和 Heroku 支持。
EDIT:
编辑:
I see that Saaspose is now called Aspose for Cloud
我看到 Saaspose 现在被称为Aspose for Cloud
Another API that claims something similar is Doxument
另一个声称类似的 API 是Doxument
回答by Deer Hunter
回答by LiamB
There doesn't seem to be any yet. See below for something that might help.
似乎还没有。请参阅下文了解可能有帮助的内容。
回答by ZhenyaUsenko
You can use mammoth to parse .docx files https://www.npmjs.com/package/mammothand xlsx to parse .xlsx files https://github.com/SheetJS/js-xlsx
您可以使用 mammoth 解析 .docx 文件https://www.npmjs.com/package/mammoth和 xlsx 解析 .xlsx 文件https://github.com/SheetJS/js-xlsx