Last active
August 31, 2016 02:24
-
-
Save ahgood/40226282c4b6c127b1ccadf155862f19 to your computer and use it in GitHub Desktop.
Drag & Drop Upload and Parse Spreadsheet(xls, xlsx)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Drag & Drop Upload and Parse Spreadsheet(xls, xlsx)</title> | |
</head> | |
<body> | |
<style> | |
#dropZone { | |
width: 400px; | |
height: 100px; | |
background-color: #eee; | |
border: 1px solid #ccc; | |
margin-bottom: 20px; | |
padding: 10px; | |
} | |
</style> | |
<div id="dropZone" ondrop="drop_handler(event)" ondragover="dragover_handler(event)">Drop Zone</div> | |
<script src="dist/xlsx.core.min.js"></script> | |
<script> | |
var workbook; | |
function dragover_handler(e) { | |
e.preventDefault(); | |
e.dataTransfer.dropEffect = "move" | |
} | |
function drop_handler(e) { | |
e.preventDefault(); | |
var files = e.dataTransfer.files; | |
var i,f; | |
for (i = 0, f = files[i]; i != files.length; ++i) { | |
var reader = new FileReader(); | |
var name = f.name; | |
reader.onload = function(e) { | |
var data = e.target.result; | |
workbook = XLSX.read(data, {type: 'binary'}); | |
var worksheet = workbook.Sheets[workbook.SheetNames[0]]; | |
//Get the value of A1 cell | |
console.log(worksheet['A1'].v); | |
}; | |
reader.readAsBinaryString(f); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/SheetJS/js-xlsx