Sample Array Script for Spreadsheet
This is a Sample Array Script for Spreadsheet. It makes an 2D array filled by strings and number. The strings and number are column strings and row number, respectively.
However, because this is a sample, the maximum column number is 26.
function sa(row, col){
if (col > 26) return;
var ar = new Array(row);
for(var i = 0; i < row; i++) ar[i] = new Array(col);
for (var i = 0; i < row; i++){
for (var j = 0; j < col; j++){
ar[i][j] = String.fromCharCode(i + 97) + String(j + 1);
}
}
return ar.map(function(x, i){return x.map(function(y, j){return ar[j][i]})});
}
When “sa(10,10)” is given, following array can be output.