Javascript 读取excel文件并以html显示

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34852740/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:56:58  来源:igfitidea点击:

Read excel file and display in html

javascripthtmlangularjs

提问by Nitin Agarwal

I have an excel file that contains data. I want to read that file and display the results in html / web page using JS or Angular JS.

我有一个包含数据的excel文件。我想读取该文件并使用 JS 或 Angular JS 在 html/网页中显示结果。

回答by catamphetamine

A very simple way of reading an *.xslx file in a browser:

在浏览器中读取 *.xslx 文件的一种非常简单的方法:

(displaying the results in html / web page using JS or Angular JS is trivial after that, though I'd suggest React over Angular)

(之后使用 JS 或 Angular JS 在 html/web 页面中显示结果是微不足道的,尽管我建议 React 而不是 Angular)

https://catamphetamine.github.io/read-excel-file/

https://catamphetamine.github.io/read-excel-file/

<input type="file" id="input" />
import readXlsxFile from 'read-excel-file'

const input = document.getElementById('input')

input.addEventListener('change', () => {
  readXlsxFile(input.files[0]).then((data) => {
    // `data` is an array of rows
    // each row being an array of cells.
  })
})

In the example above datais raw string data. It can be parsed to JSON with a strict schema by passing schemaargument. See API docs for an example of that.

在上面的例子中data是原始字符串数据。可以通过传递schema参数将其解析为具有严格模式的 JSON 。有关示例,请参阅 API 文档。

API docs: http://npmjs.com/package/read-excel-file

API 文档:http: //npmjs.com/package/read-excel-file

回答by Clever Programmer

SheetsJS/js-xlsxGithub repository is designed for working with XLSX files in web development. This would be really useful for you. Read up on this and learn how to use it, no need to reinvent the wheel either. Good luck.

SheetsJS/js-xlsxGithub 存储库设计用于在 Web 开发中处理 XLSX 文件。这对你真的很有用。阅读并学习如何使用它,也无需重新发明轮子。祝你好运。

回答by Madhu

JsZipdid this very efficently. Take a look at it. And refer linkto read local file using JSZip, you can then need to process to get the data in the excel file. Digging through the help documents will let you know how to do so.

JsZip非常有效地做到了这一点。看一看。并参考链接使用JSZip读取本地文件,然后您可以需要处理以获取excel文件中的数据。仔细阅读帮助文档会让您知道如何操作。