I want to convert excel file to json but it shows error saying : Type Error ..cannot read the property 'target' of undefined
I tried all that I could but couldn't get rid of this error. There is no documentation for the same anywhere.
Below is my code
<template>
<div>
<div class="conatiner mt-5">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3">
<input class="form-control" type="file" id="input" accept=".xls, .xlsx" />
</div>
<div class="col-md-2">
<button class="btn btn-primary" id="button" v-on:click="previewFiles()">Convert</button>
</div>
<div class="col-md-12">
<pre id="jsondata"></pre>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {};
},
function() {
oFileIn = document.getElementById('my_file_input');
if(oFileIn.addEventListener(){ oFileIn.addEventListener('change', filePicked, false);
} },
methods:{
previewFiles(e){
// Get The File From The Input var oFile = e.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) }); }; reader.readAsBinaryString(oFile) },
// Tell JS To Start Reading The File.. You could delay this if desired
},
};
</script>
Please help me out with this.. Thanks in advance!!