- First row: Data name
- Second row: Data value
- Third row: Data name in the desired order
name: < /th>
< /th>
b < /th>
e < /th>
d < /th>
< /th> < /tr> < /tr> < /th> < /tr> < /th> < /tr> < /th> < /tr> < /th> < /tr> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> />
значение: < /td>
10 < /td>
2 < /td>
35 < /td>
4 < /td>
12
< /td>
12
/>order :
A
B
C
D
E
the result it did before, with empty name at the end:
name :
A
B
C
d < /th>
e < /th>
"" < /th>
< /tr>
< /thead>
: < /td>
10 < /td>
/> 12 < /td>
4 < /td>
35 < /td>
"" < /td>
< /tr>
< /tbody>
< /table> < /div>
. class = "s-table-container">
name: < /th>
a < /th>
d < /th>
c < /th>
< /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> /> e < /th>
< /tr>
< /thead>
значение: < /td>
10 < /td>
4 < /td>
12
< /td>
12
/> 2 < /td>
35 < /td>
< /tr>
< /tbody>
< /table> < /div>
data:
https://docs.google.com/spreadsheets/d/ ... drive_link> function test() {
var objects = spreadsheet.getSheetByName("Feuille 121").getRange("A1:GG2").getValues()
var order = spreadsheet.getSheetByName("Feuille 121").getRange("A3:GG3").getValues().flat()
objects = Object.keys(objects[0]).map(function(c) {
return objects.map(function(r) {
return r[c];
});
});
order = Object.keys(order[0]).map(function(c) {
return order.map(function(r) {
return r[c];
});
});
// organise dans l'ordre des paramètre
let orderIndex = {}
order.forEach((value, index) => orderIndex[value] = index);
// Sort
objects.sort((a, b) => orderIndex[a[0]] - orderIndex[b[0]]);
var length = objects.length
objects = Object.keys(objects[0]).map(function(c) {
return objects.map(function(r) {
return r[c];
});
});
console.log(objects)
spreadsheet.getSheetByName("Feuille 121").getRange(1, 1, 2, length).setValues(objects)
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... a-1d-array
Мобильная версия