Wijmo FlexSheet - load
Import excel file to FlexSheet using the load method (synchronous)
by Joel Parks
HTML
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.filter.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.sheet.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.xlsx.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.xlsx.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.grid.xlsx.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<div class="container">
<h1>
FlexSheet Import
</h1>
<p>This FlexSheet imports a file <b>synchronously</b></p>
<div class="form-inline">
<input type="file"
id="importFile"
class="form-control"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<!-- <button class="btn btn-default">Load</button> -->
</div>
<div id="flexSheet" style="height:400px;"></div>
</div>
JavaScript
var countries = 'US,Germany,UK,Japan,Italy,Greece'.split(','),
data = [];
for (var i = 0; i < countries.length; i++) {
data.push({
country: countries[i],
downloads: Math.round(Math.random() * 20000),
sales: Math.round(Math.random() * 10000),
expenses: Math.round(Math.random() * 5000)
});
}
// create the FlexSheet control
var flexSheet = new wijmo.grid.sheet.FlexSheet('#flexSheet');
var importFile = document.getElementById('importFile');
importFile.addEventListener('change', function() {
loadWorkbook();
});
function loadWorkbook(){
var reader;
var file = importFile.files[0];
if(file){
//
reader = new FileReader();
reader.onload = function (e) {
flexSheet.load(reader.result);
console.log(reader.result);
};
reader.readAsArrayBuffer(file);
}
flexSheet.columns[0].format = 'n4';
console.log(flexSheet);
}
// create and add a new sheet the control
var sheet = new wijmo.grid.sheet.Sheet();
sheet.name = "New Sheet";
sheet.itemsSource = data;
flexSheet.sheets.push(sheet);
// push a new empty sheet onto the sheets array
var emptysheet = new wijmo.grid.sheet.Sheet(flexSheet, null, "Empty Sheet")
flexSheet.sheets.push(emptysheet);