I need to read line-by-line through an Excel spreadsheet which is stored locally on my computer and create HTML elements for each line. Ideally this would change the page if the original Excel document is changed.
I'm using vanilla Javascript. What library / other method should I use to read the spreadsheet?
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/jszip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.js"></script>
var exportExcelToJson = 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 xlObject = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
var json_object = JSON.stringify(xlObject);
console.log(json_object);
})
};
reader.onerror = function(sendErr) {
console.log(sendErr);
};
reader.readAsBinaryString(file);
};
};
</script>
It's a function converts the Excel sheet type XLSX data to JSON and you can add promise to the function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments