简体   繁体   English

在 Node.JS 中解析 Microsoft Office 文件

[英]Parse Microsoft Office files in Node.JS

I'm working on a web application where users can upload Microsoft Office Document files.我正在开发一个 Web 应用程序,用户可以在其中上传 Microsoft Office 文档文件。 Right now, our server is running Node.JS with Express.js and we're hosted on Heroku.现在,我们的服务器运行 Node.JS 和 Express.js,我们托管在 Heroku 上。 Because of this, I don't think that I can install programs such as abiword or catdoc.因此,我认为我无法安装诸如 abiword 或 catdoc 之类的程序。 I can handle the file uploads, but can't parse the contents of the document.我可以处理文件上传,但无法解析文档的内容。

How can I read the contents of the doc file?如何读取 doc 文件的内容? The information will then be put into a database.然后将信息放入数据库。 It'd be nice to preserve basic formatting (bold, italic, underline), but not essential.保留基本格式(粗体、斜体、下划线)会很好,但不是必需的。

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.虽然您似乎无法使用 NPM 获得任何可以直接执行 Word 的东西,但您或许可以使用 REST API 通过另一个云服务来请求它。 For example Saaspose (they of the famous Aspose tools) have public API for Word , Excel , PDF , and others.例如Saaspose (它们是著名的 Aspose 工具)具有WordExcelPDF等的公共 API。 They list node.js, javascript, and Heroku support on their page.他们在他们的页面上列出了 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

Office package: npm install office seems to provide at least part of the answer. Office包: npm install office似乎至少提供了部分答案。 I use it to read Excel files, so far have not tried any Word docs.我用它来读取 Excel 文件,到目前为止还没有尝试过任何 Word 文档。

There doesn't seem to be any yet.似乎还没有。 See below for something that might help.请参阅下文了解可能有帮助的内容。

Can I read PDF or Word Docs with Node.js? 我可以使用 Node.js 阅读 PDF 或 Word 文档吗?

您可以使用 mammoth 解析 .docx 文件https://www.npmjs.com/package/mammoth和 xlsx 解析 .xlsx 文件https://github.com/SheetJS/js-xlsx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM