Created
September 1, 2016 17:07
-
-
Save knoonrx/0cda3f78db244f488036e6feef280247 to your computer and use it in GitHub Desktop.
This file contains 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"> | |
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"> | |
<title>XLSX Reader JS</title> | |
<link rel="stylesheet" href="screen.css" media="screen"> | |
</head> | |
<body> | |
<input type="file" id="my_file_input" /> | |
<div id='my_file_output'></div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script> | |
<script> | |
var oFileIn; | |
$(function() { | |
oFileIn = document.getElementById('my_file_input'); | |
if(oFileIn.addEventListener) { | |
oFileIn.addEventListener('change', filePicked, false); | |
} | |
}); | |
function filePicked(oEvent) { | |
// Get The File From The Input | |
var oFile = oEvent.target.files[0]; | |
var sFilename = oFile.name; | |
// Create A File Reader HTML5 | |
var reader = new FileReader(); | |
// Ready The Event For When A File Gets Selected | |
reader.onload = function(e) { | |
var data = e.target.result; | |
var cfb = XLS.CFB.read(data, {type: 'binary'}); | |
var wb = XLS.parse_xlscfb(cfb); | |
// Loop Over Each Sheet | |
wb.SheetNames.forEach(function(sheetName) { | |
// Obtain The Current Row As CSV | |
var sCSV = XLS.utils.make_csv(wb.Sheets[sheetName]); | |
var oJS = XLS.utils.sheet_to_row_object_array(wb.Sheets[sheetName]); | |
$("#my_file_output").html(sCSV); | |
console.log(oJS) | |
}); | |
}; | |
// Tell JS To Start Reading The File.. You could delay this if desired | |
reader.readAsBinaryString(oFile); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment