简体   繁体   English

如何对多个Google工作表中的特定列进行排序

[英]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.

相关问题 我该如何编写Google表格脚本来对特定列进行排序,并删除所有不在特定字符串数组中的内容 - How can I write a google sheets script that will sort through a particular column and delete everything that is not in a specific array of strings 如何在 Google 表格中为宏(google-sheets、filter、if、else、script)中的特定激活值空列过滤器使用 if 条件? - How to use if condition for specific activated value empty column filter in Google Sheets for macro (google-sheets, filter, if, else, script)? 如何使用 Google Script 从 Google 表格中提取特定列? - How do I extract a specific Column from google sheets using Google Script? 如何定位和迭代 Google 表格/应用程序脚本中的一个特定列(按列名)? - How to target and iterate through just one specific column (by column name) in Google sheets / apps script? 使用单列作为Google表格中的键对行进行排序 - Sort rows using a single column as the key in Google Sheets Google 表格中的自定义排序 - Custom Sort in Google Sheets 删除多列,然后在Google表格中按价格排序(脚本编辑器) - Delete multiple columns, then sort by price in Google Sheets (Script Editor) Google Apps Script - 如何将此代码应用于 Google 表格中的多个表格 - Google Apps Script - how to applies this code for multiple sheets in google sheets 如何按特定字符串搜索 Google 表格? - How to search a Google Sheets by specific string? 如何解码谷歌表格中的特定字符(unicode) - How to decode specific characters (unicode) in Google Sheets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM