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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
Disclaimer: I am the author of Alasql.
In this example:
- 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>