- Notifications
You must be signed in to change notification settings - Fork689
How to upload form for txt and xlsx in javascript
Source:StackOverflow.com,StackOverflow.com
I would like to make a form that allow user upload .txt and .xlsx file and write this file's contents in a div.I don't know if i should go server side to handle uploaded files.
I want to read the file uploaded by users on the client side and then do processing on them, instead of doing it on server-side. Is it possible read files and do manipulation using javascript on client side.
You can read CSV or XLSX data with AlaSQL library. It usesjs-xlsx library.
If you read data from server:
alasql(['SELECT * FROM XLSX("data/myfile")']).then(function(data){// process data array});
If you are reading data from the browser:
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.3.7/alasql.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.9.2/xlsx.core.min.js"></script><p>Select CSV file to read:</p><inputid="readfile"type="file"onchange="loadFile(event)"/><script>functionloadFile(event){alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(data){// Process data here});}</script>
AlaSQL automatically recognize file type by file extension.
Seethis jsfiddle for a live example
© 2014-2026,Andrey Gershun &Mathias Rangel Wulff
Please help improve the documentation by opening a PR on thewiki repo