bob*_*oca 7 sorting google-sheets google-apps-script
我正试图弄清楚如何自动按字母顺序对表单进行排序.每当我在AC列下放一个新条目时,我希望它能自动与其余数据一起排序.
我听说必须使用Google应用脚本完成此操作.任何人都可以帮助我吗?
提前致谢!
https://docs.google.com/spreadsheets/d/1XH4mrKa6W4se5WwM6oKqh959gG2kAQVtAmOnml13VoE/edit#gid=0
Ser*_*sas 22
电子表格很容易从脚本中排序,脚本可以通过电子表格"事件"轻松触发.
onEdit
是这些事件中的一个应该适合您的需求.在这里
和这里.
然后排序过程显示在doc中,我重现下面的代码:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("A1:C7");
// Sorts by the values in the first column (A)
range.sort(1);
// Sorts by the values in the second column (B)
range.sort(2);
// Sorts descending by column B
range.sort({column: 2, ascending: false});
// Sorts descending by column B, then ascending by column A
// Note the use of an array
range.sort([{column: 2, ascending: false}, {column: 1, ascending: true}]);
// For rows that are sorted in ascending order, the "ascending" parameter is
// optional, and just an integer with the column can be used instead. Note that
// in general, keeping the sort specification consistent results in more readable
// code. We could have expressed the earlier sort as:
range.sort([{column: 2, ascending: false}, 1]);
// Alternatively, if we wanted all columns to be in ascending order, we would use
// the following (this would make column 2 ascending)
range.sort([2, 1]);
// ... which is equivalent to
range.sort([{column: 2, ascending: true}, {column: 1, ascending: true}]);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
23567 次 |
最近记录: |