gpt4 book ai didi

sorting - 纸张自动排序

转载 作者:行者123 更新时间:2023-12-02 06:26:40 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何按字母顺序自动对工作表进行排序。每当我在 A-C 列下放置一个新条目时,我希望它能够自动与其余数据一起排序。

我听说这必须使用 Google Apps 脚本来完成。谁能帮我解决这个问题吗?

提前致谢!

https://docs.google.com/spreadsheets/d/1XH4mrKa6W4se5WwM6oKqh959gG2kAQVtAmOnml13VoE/edit#gid=0

最佳答案

电子表格可以轻松地通过脚本进行排序,并且脚本可以轻松地由电子表格“事件”触发。

onEdit 是应该满足您的需求的事件之一。 Doc herehere .

那么排序过程就是shown in the 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}]);

关于sorting - 纸张自动排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35563652/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com