Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to upload form for txt and xlsx in javascript

Mathias Rangel Wulff edited this pageMar 14, 2017 ·9 revisions

How to upload form for txt and xlsx in javascript?

Source:StackOverflow.com,StackOverflow.com

Questions

  1. 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.

  2. 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.

Answer

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

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp