Flexsheet

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.input.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.filter.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.grid.sheet.min.js"></script>
<div id="sheet">
</div>
<br><br>
<div>
    Sum:
    <p id="sum"></p>
    Avg:
    <p id="avg"></p>
</div>

CSS

body {
    margin: 40px;
}

.wj-flexsheet {
    width: 700px;
    height: 400px;
}

JavaScript

onload = function() {
    var sum = 0,
        avg = 0,
        count = 0;
    var eleSum = document.getElementById('sum');
    var eleAvg = document.getElementById('avg');
    var formatSheet = new wijmo.grid.sheet.FlexSheet('#sheet', {
        selectionMode: 'CellRange',
        selectionChanged: function(s, e) {
            var selections = s.selectedSheet.selectionRanges;
            if (selections.length == 0) {
                eleSum.innerHTML = '';
                eleAvg.innerHTML = '';
                return;
            }
            sum = avg = count = 0;
            // for each of the selections in the sheet
            selections.forEach((lastSel) => {
                for (let col = lastSel.leftCol; col <= lastSel.rightCol; col++) {
                    for (let row = lastSel.topRow; row <= lastSel.bottomRow; row++) {
                        let val = formatSheet.getCellData(row, col, false);
                        if (wijmo.isNumber(val)) {
                            sum += val;
                            count++;
                        }
                    }
                }
            });
            let lastSel = s.selection;
            if (selections.indexOf(lastSel) == -1) {
            	// for the last selection
                for (let col = lastSel.leftCol; col <= lastSel.rightCol; col++) {
                    for (let row = lastSel.topRow; row <= lastSel.bottomRow; row++) {
                        let val = formatSheet.getCellData(row, col, false);
                        if (wijmo.isNumber(val)) {
                            sum += val;
                            count++;
                        }
                    }
                }
            }
            avg = sum / count;
            eleSum.innerHTML = sum;
            eleAvg.innerHTML = avg;
        }
    });
    var sheet = new wijmo.grid.sheet.Sheet(formatSheet, null, 'Number', 20, 8);
    formatSheet.sheets.push(sheet);

    formatSheet.deferUpdate(() => {
        var...