Skip to content

Instantly share code, notes, and snippets.

@theredstapler
Created July 23, 2016 16:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save theredstapler/5ce6a43b066dbe0cac3fa5587835be91 to your computer and use it in GitHub Desktop.
Save theredstapler/5ce6a43b066dbe0cac3fa5587835be91 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Excel to JSON Demo</title>
<script src="xlsx.full.min.js"></script>
</head>
<body>
<script>
/* set up XMLHttpRequest */
var url = "test.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(e) {
var arraybuffer = oReq.response;
/* convert data to binary string */
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
/* Call XLSX */
var workbook = XLSX.read(bstr, {type:"binary"});
/* DO SOMETHING WITH workbook HERE */
var first_sheet_name = workbook.SheetNames[0];
/* Get worksheet */
var worksheet = workbook.Sheets[first_sheet_name];
console.log(XLSX.utils.sheet_to_json(worksheet,{raw:true}));
}
oReq.send();
</script>
</body>
</html>
@rohitmore1995
Copy link

how can we access json data

@rohitmore1995
Copy link

how can we access json data like, if I select a particular name then how can I display other information like middlename age

@tanishraj
Copy link

How can we implement the same in Vue 2.0???

@marcumo
Copy link

marcumo commented Nov 23, 2019

How can we implement the same in Vue 2.0???

Yes, you only need to add <script src="xlsx.full.min.js"></script>

@klementus
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment