如何使用JavaScript从excel(xlsx,csv)导入数据到HTML页面? [英] How can I import data from excel (xlsx, csv) to a HTML page using JavaScript?

查看:3507
本文介绍了如何使用JavaScript从excel(xlsx,csv)导入数据到HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H!
我有一个.xlsx和.html文件。如何使用JavaScript将xlsx文件导入我的html文件,我已经观看了Lynda:JavaScript Essential Training by Simon Allardice,没有得到任何线索如何做到这一点! Googled很多,还在这里。
尝试类似的问题...
只需要一个脚本将其复制到我的html文件,然后我的html文件可以读取xlsx并显示在浏览器中!

H! I have a .xlsx and .html files. How can I import the xlsx file to my html file using JavaScript, I already watched Lynda: JavaScript Essential Training by Simon Allardice and didn't get any clue how to do this! Googled a lot and still here. Tried the similar questions... Just need a script to copy it into my html file, and then my html file can read the xlsx and display it in the browser!

推荐答案

您可以使用 Alasql JavaScript SQL库,它有特殊的功能读取XLSX文件并放入HTML页面。它使用 js-xlsx 库读取XLSX文件。

You can use Alasql JavaScript SQL library, which has special functionality to read XLSX files and put in HTML page. It uses js-xlsx library to read XLSX files.

免责声明:我是Alasql的作者。

Disclaimer: I am the author of Alasql.

在此示例中:


  • Alasql从cdn.rawgit.com获取Excel文件(您可以将其替换为您的地址

  • Alasql将结果表放到DIV,id =res

  • {headers:true}标志表示Alasql读取和写入标题

  • 您可以将CSV文件 -

  • 出于生产目的,将alasql.min.js和xlsx.core.min.js下载到您的服务器或使用CDN。
  • 只需将xlsx()替换为CSV / li>
  • Alasql takes Excel file from cdn.rawgit.com (you can replace it with your address
  • Alasql put result table to DIV with id="res" - you can change the name or add CSS to prettify result table
  • {headers:true} flag means that Alasql reads and writes headers
  • You can read CSV files as well - just replace XLSX() to CSV() in the example
  • For production purpose download alasql.min.js and xlsx.core.min.js to your server or use CDN.

查看下面有效的代码段:

See the working code snippet below:

alasql('select * into html("#res",{headers:true}) \
  from xlsx("https://cdn.rawgit.com/agershun/alasql/version-0.0.36/test/test168.xlsx",\
            {headers:true})')

<script src="https://cdn.jsdelivr.net/alasql/0.3/alasql.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.7.12/xlsx.core.min.js"></script>

<div id="res"></div>

这篇关于如何使用JavaScript从excel(xlsx,csv)导入数据到HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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