gpt4 book ai didi

sorting - Google Script 排序故障排除(作为 2 个函数使用但不合并)

转载 作者:行者123 更新时间:2023-12-02 14:55:14 25 4
gpt4 key购买 nike

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

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

}

最佳答案

您可以尝试添加 flush()两个 Action 之间的方法。

flush()

Applies all pending Spreadsheet changes.

Spreadsheet operations are sometimes bundled together to improve performance, such as when doing multiple calls to Range.getValue(). However, sometimes you may want to make sure that all pending changes are made right away, for instance to show users data as a script is executing.

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

}

关于sorting - Google Script 排序故障排除(作为 2 个函数使用但不合并),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53282414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com