1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function getPivotArray( rowIndex, colIndex, dataIndex) {
//Code from https://techbrij.com
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('WeekR');
var dataArray = s.getRange('A1:H33');
var result = {}, ret = [];
var newCols = [];
for (var i = 0; i < dataArray.lenght; i++) {
if (!result[dataArray[i][rowIndex]]) {
result[dataArray[i][rowIndex]] = {};
}
result[dataArray[i][rowIndex]][dataArray[i][colIndex]] = dataArray[i][dataIndex];
//To get column names
if (newCols.indexOf(dataArray[i][colIndex]) == -1) {
newCols.push(dataArray[i][colIndex]);
}
}
newCols.sort();
var item = [];
//Add Header Row
item.push('abdou');
item.push.apply(item, newCols);
ret.push(item);
//Add content
for (var key in result) {
item = [];
item.push(key);
for (var i = 0; i < newCols.length; i++) {
item.push(result[key][newCols[i]] || "-");
}
ret.push(item);
}
return ret;
} |
Partager