Google Script排序故障排除(作为2个功能但不合并)

Nic*_*ick 1 sorting google-sheets google-apps-script

我的工作与谷歌Apps脚本在列D.列D的号码数量在AC列中的数据进行排序依赖于列中的数据交流(见下文).

https://docs.google.com/spreadsheets/d/11QSZPAl3nCs7nzpZIR4FzjfkPUyBBut1pD2K0919UB8/edit?usp=sharing

我试图让它在顶部有一个空行(在A6:C6中),因此可以输入新数据,然后在排序时它将向下移动到主列表(A7:C299)和一个新的空行将再次出现在A6:C6中.

我试图通过移动新条目表底部,然后有它像是这样做,但出于某种原因,一旦它已被移动并不新条目排序.如果我删除了排序的代码,它会正确移动,如果我只是要对代码进行排序(在它复制粘贴A6:C6中的数据之后),它也可以工作,但是当这些功能合并时它不会吨.任何想法或其他方式来实现这一目标?谢谢!

function SortList() {

var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange("A7:D299");

// Takes values in first row, moves then to end of list and clears contents in first row, then sorts list

var copyrange = sheet.getRange("A6:C6");
var pasterange = sheet.getRange("A298:C298");
var copyvalues = copyrange.getValues();


pasterange.setValues(copyvalues); 
copyrange.clearContent();

// Sorts by the values in the first column (A)
range.sort({column: 4, ascending: false});

}
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以尝试flush()在两个操作之间添加方法.

齐平()

应用所有待处理的电子表格更改.

有时将电子表格操作捆绑在一起以提高性能,例如在对Range.getValue()进行多次调用时.但是,有时您可能希望确保立即进行所有挂起的更改,例如在脚本执行时向用户显示数据.

function SortList() {

var sheet = SpreadsheetApp.getActiveSpreadsheet();
var range = sheet.getRange("A7:D299");

// Takes values in first row, moves then to end of list and clears contents in first row, then sorts list

var copyrange = sheet.getRange("A6:C6");
var pasterange = sheet.getRange("A298:C298");
var copyvalues = copyrange.getValues();

pasterange.setValues(copyvalues); 
copyrange.clearContent();

//Flush
SpreadsheetApp.flush();

// Sorts by the values in the first column (A)
range.sort({column: 4, ascending: false});

}
Run Code Online (Sandbox Code Playgroud)