Skip to main content

Demo

Input

Output


My Spreadsheet

ABCDEFGHIJ
112345678910
211121314151617181920
321222324252627282930

Define a range handler

i.current.setRangeHandler((left : string, right: string) => {
    const colLeft = left[0];
    const rowLeft = Number(left[1]);
    const colRight = right[0];
    const rowRight = Number(right[1]);
    const cell2index = {
        "A": 0,
        "B": 1,
        "C": 2,
        "D": 3,
        "E": 4,
        "F": 5,
        "G": 6,
        "H": 7,
        "I": 8,
        "J": 9
    }
    const result = [];
    for(let i = cell2index[colLeft]; i <= cell2index[colRight]; i++) {
        for(let j = rowLeft - 1; j <= rowRight - 1; j++) {
            const element = dataSource[j][i];
            result.push(element);
        }
    }
    return result;
});

Define a cell reference handler

i.current.setCellRefHandler((cellName, fail) => {
    if(cellName.length > 2) fail('Wrong cell reference');
    const col = cellName[0];
    const row = Number(cellName[1]);
    const cell2index = {
        "A": 0,
        "B": 1,
        "C": 2,
        "D": 3,
        "E": 4,
        "F": 5,
        "G": 6,
        "H": 7,
        "I": 8,
        "J": 9
    }
    return dataSource[row - 1][cell2index[col]];
});