Google Apps脚本其他排序规则 [英] Google Apps Script Additional Sorting Rules
问题描述
我正在研究Google Apps脚本电子表格应用程序,我希望程序具有的功能之一是根据来自2个不同列的数据自动对一系列表单回复进行排序。所以我想按第16列中的数据对它进行排序,然后按列1排序。我可以使用以下方法手动实现此功能:
https://drive.googleblog.com/2010/06/tips-tricks-advanced-sorting-rules-in .html
目前我正在运行 Spreadsheet.sort(列,升序)
函数第一列,但我无法对其进行排序,因此它将接受第二列作为附加排序规则。在Google Apps脚本中是否有可用于模拟此功能的方法? 请参阅文档:
< href =https://developers.google.com/apps-script/reference/spreadsheet/range#sort(Object)> https://developers.google.com/apps-script/reference/spreadsheet/range# sort(Object)
$ b
函数sortFormResponses(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
//将工作表名称更改为工作表名称
var s = ss.getSheetByName(Form Responses);
var lastCol = s.getLastColumn();
var lastRow = s.getLastRow();
//假设行1中的标题
var r = s.getRange(2,1,lastRow - 1,lastCol);
//注意使用数组
r.sort([{column:1,ascending:true},{column:16,ascending:true}]);
}
I am working on a Google Apps Script spreadsheet application, and one of the abilities I would like the program to have is to automatically sort a series of form responses based on data from 2 different columns. So I would want to sort it by the data in column 16 and then sort by column 1. I can achieve this functionality manually using the method at: https://drive.googleblog.com/2010/06/tips-tricks-advanced-sorting-rules-in.html
Currently I am running the Spreadsheet.sort(column, ascending)
function with the first column, but I cannot make it sort so that it will accept the second column as an additional sorting rule. Is there a method in Google Apps Script that I could use to emulate this functionality?
See doc: https://developers.google.com/apps-script/reference/spreadsheet/range#sort(Object)
function sortFormResponses() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// change name of sheet to your sheet name
var s = ss.getSheetByName("Form Responses");
var lastCol = s.getLastColumn();
var lastRow = s.getLastRow();
// assumes headers in row 1
var r = s.getRange(2, 1, lastRow - 1, lastCol);
// Note the use of an array
r.sort([{ column: 1, ascending: true }, { column: 16, ascending: true}]);
}
这篇关于Google Apps脚本其他排序规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!