So I have three same name column in excel. I want to get all of it and display in HTML table using push. the problem is. i only get the last item. I'm not the great in English so i hope u guys all understand.
const bulkFileENU = document.getElementById('bulkFileENU');
var ExcelToJSON = function () {
this.parseExcel = function (file) {
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});
workbook.SheetNames.forEach(function (sheetName) {
var XL_row_object = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
var json_object = JSON.stringify(XL_row_object);
var asdf = (JSON.parse(json_object));
DisplayObjectENU(asdf)
})
};
reader.onerror = function (ex) {
console.log(ex);
};
reader.readAsBinaryString(file);
};
};
bulkFileENU.addEventListener('change', function (evt) {
var files = evt.target.files;
var xl2json = new ExcelToJSON();
xl2json.parseExcel(files[0]);
});
function DisplayObjectENU(excelData) {
var tableExcel = document.getElementById('excelBulkENUTable');
excelData.forEach((x) => {
tableExcel.innerHTML +=
`<tr style="text-align:center">` +
`<td id="QuesName">${x.QuesName}</td>` +
`<td id="CorrectAnswer">${x.CorrectAnswer}</td>` +
`<td id="WrongAnswer">${x.WrongAnswer}</td>` +
`<td id="QuesPoints">${x.QuesPoints}</td>` +
`</tr>`
});
}
table,tbody,td{
border: 1px solid black;
}
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
<div class="modal-body">
<input type=file name="files[]" id='bulkFileENU' />
</div>
<div class="form-group">
<table id="bulkFileENU" class="table table-bordered" style="">
<thead>
<tr>
<tr>
<th class="align-middle" style="text-align:center">Questions</th>
<th class="align-middle" style="text-align:center">Choices</th>
<th class="align-middle" style="text-align:center">Answer</th>
<th class="align-middle" style="text-align:center">Points</th>
</tr>
</thead>
<tbody id="excelBulkENUTable"></tbody>
</table>
</body>