Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  179] [ 5]  / answers: 1 / hits: 20955  / 10 Years ago, sun, january 11, 2015, 12:00:00

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!


More From » html

 Answers
20

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>




[#68250] Thursday, January 8, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ignacio

Total Points: 467
Total Questions: 128
Total Answers: 79

Location: Luxembourg
Member since Tue, Mar 14, 2023
1 Year ago
;