Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting Google脚本排序疑难解答(作为两个函数工作,但不合并)_Sorting_Google Apps Script_Google Sheets - Fatal编程技术网

Sorting Google脚本排序疑难解答(作为两个函数工作,但不合并)

Sorting Google脚本排序疑难解答(作为两个函数工作,但不合并),sorting,google-apps-script,google-sheets,Sorting,Google Apps Script,Google Sheets,我正在使用google apps脚本,按D列中的数字对a-C列中的数据进行排序。D列的数字取决于a-C列中的数据(见下文) 我试图使它在顶部有一个空行(在A6:C6中),这样就可以输入新数据,然后在排序后,它将向下移动到主列表(A7:C299),并且一个新的空行将再次出现在A6:C6中 我尝试将新条目移动到工作表的底部,然后对其进行排序,但由于某种原因,它不会在移动新条目后对其进行排序。如果我删除了用于排序的代码,它会正确地移动,如果我只有要排序的代码(在它复制粘贴了A6:C6中的数据之后),

我正在使用google apps脚本,按D列中的数字对a-C列中的数据进行排序。D列的数字取决于a-C列中的数据(见下文)

我试图使它在顶部有一个空行(在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});

}
您可以尝试在两个操作之间添加该方法

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});

}