首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改google sheets中的排序范围

更改google sheets中的排序范围
EN

Stack Overflow用户
提问于 2019-03-13 23:04:38
回答 1查看 27关注 0票数 0

我有:

代码语言:javascript
运行
复制
 function sortWDSheet()
  {

     var ss = SpreadsheetApp.getActiveSpreadsheet();
    var source_sheet = ss.getSheetByName("WD");
    var source_sheet_last_row = source_sheet.getLastRow();
    source_sheet.getRange('A3:B'+(source_sheet_last_row-1)).sort({column: 1, 
    ascending: true});


  }

但实际上我想对A3:I进行排序,而不是对列C、D、E和F进行排序,如果这有任何意义的话。

任何帮助都将不胜感激:)

EN

回答 1

Stack Overflow用户

发布于 2019-03-13 23:33:35

尝试其中的多个sorting.pick up,真正满足您的需求。

出处:https://stackoverflow.com/a/35563828/9599873

代码语言:javascript
运行
复制
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}]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55145095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档