index.js
// ... finally take the calculated total and insert into the HTML table
finally take the calculated total and insert into the HTML table
finally take the calculated total and insert into the HTML table
function calculateCell(row, column){
    var tokenArray = getFormula(tblArray[row][column]);
    if (tokenArray !== null){
        var fromColumn = tokenArray[1].substr(0, 1);
        var fromRow = tokenArray[1].substr(1, tokenArray[1].length - 1);
        var toColumn = tokenArray[2].substr(0, 1);
        var toRow = tokenArray[2].substr(1, tokenArray[2].length - 1);
        var fromRowIndex = parseFloat(fromRow) - 1;
        var fromColIndex = fromColumn.charCodeAt(0) - 65;
        var toRowIndex = parseFloat(toRow) - 1;
        var toColIndex = toColumn.charCodeAt(0) - 65;
        var sumTotal = 0;
        for (var i = fromRowIndex; i <= toRowIndex; i++){
            for (var j = fromColIndex; j <= toColIndex; j++){
                if (isCellRef(tblArray[i][j])) {
                    var el = tblArray[i][j].substr(1);
                    var columnString1 = el.substr(0, 1);
                    var column1 = columnString1.charCodeAt(0)-65;
                    var row1 = el.substr(1, 2);
                    row1 = parseFloat(row1)-1;
                    sumTotal += parseFloat(tblArray[row1][column1]);
                } else if (tblArray[i][j]) {
                    sumTotal += parseFloat(tblArray[i][j]);
                } else {
                    sumTotal += 0;
                }
            }   
        }
        var letter = String.fromCharCode("A".charCodeAt(0)+column);
        var cellID = `${letter}${row+1}`;
        var ref = document.getElementById(cellID);
        console.log(cellID);
        ref.innerText = sumTotal;
    }
}
function calculateCell ( row , column ) { var tokenArray = getFormula ( tblArray [ row ] [ column ] ) ; if ( tokenArray !== null ) { var fromColumn = tokenArray [ 1 ] . substr ( 0 , 1 ) ; var fromRow = tokenArray [ 1 ] . substr ( 1 , tokenArray [ 1 ] . length - 1 ) ; var toColumn = tokenArray [ 2 ] . substr ( 0 , 1 ) ; var toRow = tokenArray [ 2 ] . substr ( 1 , tokenArray [ 2 ] . length - 1 ) ; var fromRowIndex = parseFloat ( fromRow ) - 1 ; var fromColIndex = fromColumn . charCodeAt ( 0 ) - 65 ; var toRowIndex = parseFloat ( toRow ) - 1 ; var toColIndex = toColumn . charCodeAt ( 0 ) - 65 ; var sumTotal = 0 ; for ( var i = fromRowIndex ; i <= toRowIndex ; i ++ ) { for ( var j = fromColIndex ; j <= toColIndex ; j ++ ) { if ( isCellRef ( tblArray [ i ] [ j ] ) ) { var el = tblArray [ i ] [ j ] . substr ( 1 ) ; var columnString1 = el . substr ( 0 , 1 ) ; var column1 = columnString1 . charCodeAt ( 0 ) - 65 ; var row1 = el . substr ( 1 , 2 ) ; row1 = parseFloat ( row1 ) - 1 ; sumTotal += parseFloat ( tblArray [ row1 ] [ column1 ] ) ; } else if ( tblArray [ i ] [ j ] ) { sumTotal += parseFloat ( tblArray [ i ] [ j ] ) ; } else { sumTotal += 0 ; } } } var letter = String . fromCharCode ( "A" . charCodeAt ( 0 ) + column ) ; var cellID = ` ${ letter } ${ row + 1 } ` ; var ref = document . getElementById ( cellID ) ; console . log ( cellID ) ; ref . innerText = sumTotal ; } }
... finally take the calculated total and insert into the HTML table
... finally take the calculated total and insert into the HTML table
// begin by getting the formula parts // tokenArray[1] and tokenArray[2] contain the from and to references // need more validation if this was a production level app // assign the actual row/column index values for the tblArray // make sure we have a number for addition // in case cell is a litteral  // in case there are somthing // in case some cell are blank // we now have the total... insert into spreadsheet cell // ... get the cell id