Demo
My Spreadsheet
| A | B | C | D | E | F | G | H | I | J |
---|
1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
3 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
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]];
});