对多列范围排序脚本

发布于 2025-01-11 01:47:54 字数 995 浏览 0 评论 0原文


Here is a well working script which :
1- Drop a date tag in the cell H (8) for each modification in a row (I know there is something wrong in this command but it does what I am expecting...)
AND
2- Sort the whole sheet following this rule :
- column 1 : ascendent,
- column 2 : ascendent,
- column 3 : ascendent and
- column 8 ; descendent.

问题:
1- 如何将范围 (A2:K999) 添加到第二个顺序(排序)?
2- 如何向第二个命令(排序)添加触发器(按钮或菜单或其他)?

有人可以帮我吗?

function onEdit(e) {

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh0 = ss.getSheets()[0];

  var row = e.range.getRow();
  e.source.getActiveSheet().getRange(row,8).setValue(new Date());


 
var sheet = SpreadsheetApp.getActiveSheet(); 
var dataRange = sheet.getDataRange(); 
dataRange.sort([ 
  {column: 1, ascending: true}, 
  {column: 2, ascending: true}, 
  {column: 3, ascending: true}, 
  {column: 8, ascending: false} ]);


  }

Here is a well working script which :
1- Drop a date tag in the cell H (8) for each modification in a row (I know there is something wrong in this command but it does what I am expecting...)
AND
2- Sort the whole sheet following this rule :
- column 1 : ascendent,
- column 2 : ascendent,
- column 3 : ascendent and
- column 8 ; descendent.

Question :
1- how I add a range (A2:K999) to the second order (sorting) ?
2- how I add a trigger (button or menu or whatever) to the second command (sorting) ?

Can someone give me a hand ?

function onEdit(e) {

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh0 = ss.getSheets()[0];

  var row = e.range.getRow();
  e.source.getActiveSheet().getRange(row,8).setValue(new Date());


 
var sheet = SpreadsheetApp.getActiveSheet(); 
var dataRange = sheet.getDataRange(); 
dataRange.sort([ 
  {column: 1, ascending: true}, 
  {column: 2, ascending: true}, 
  {column: 3, ascending: true}, 
  {column: 8, ascending: false} ]);


  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2025-01-18 01:47:54

尝试:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("A2:K999");

function onEdit(e)  {
range.sort([{column: 1, ascending: true}, {column: 2, ascending: true}, {column: 3, ascending: true}, {column: 8, ascending: false}]);
}

try:

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("A2:K999");

function onEdit(e)  {
range.sort([{column: 1, ascending: true}, {column: 2, ascending: true}, {column: 3, ascending: true}, {column: 8, ascending: false}]);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文