Convert an XLSX File to JSON without Using a Spreadsheet Widget
Environment
Product | Progress® Kendo UI® Spreadsheet for jQuery |
Description
How can I convert an XLSX file to JSON without initializing a Spreadsheet widget?
Solution
Use a kendo.spreadsheet.Workbook
object.
<div>
1. Click to load an .xlsx file
<input type="file" name="files" id="fileForUpload" accept=".xlsx" />
</div>
<br/>
<div>
2. Click to print the file JSON on the console
<input type="button" value="Click to read file" id="btn" />
</div>
<script>
$('#btn').on('click', function() {
var file = document.getElementById("fileForUpload").files[0];
if (file) {
var workbook = new kendo.spreadsheet.Workbook({});
workbook.fromFile(file).then(function(){
var jsonContent = workbook.toJSON();
console.log(jsonContent);
})
}
});
</script>