[英]How to sort a specific column in multiple Google sheets
I'd like to sort the forth column of more than one sheet in ascending order. 我想按升序对一个以上工作表的第四列进行排序。 I can do this in the active sheet (sheet1), but can not figure out how to do it in the non-active sheets.
我可以在活动工作表(sheet1)中执行此操作,但无法弄清楚如何在非活动工作表中执行此操作。
Below is my code. 下面是我的代码。
function sort() {
var bus = SpreadsheetApp.openByUrl("URI");
var sheet = bus.getSheets()[0];
sheet.sort(4,true);
}
Instead of getting just the first sheet, get all of them in a variable (notice the absence of the zero index - [0]): 而不是仅获取第一张纸,而是将它们全部放入一个变量中(请注意,缺少零索引-[0]):
var sheets = bus.getSheets();
Then iterate through all of them in a FOR
loop: 然后在
FOR
循环中遍历所有这些对象:
for( sheet in sheets)
sheets[ sheet ].sort(4,true);
That will sort every sheet in the active Spreadsheet, you can also open sheets by ID, URL, name and the position in Spreadsheet, to find the methods you want just read the documentation . 这将对活动电子表格中的每个工作表进行排序,您还可以按ID,URL,名称和电子表格中的位置打开工作表,以查找您想要的方法,只需阅读文档即可 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.