gpt4 book ai didi

Google Apps Script unusual behaviour(Google Apps脚本异常行为)

转载 作者:bug小助手 更新时间:2023-10-25 12:09:01 25 4
gpt4 key购买 nike



I have a 5 sheets google spreadsheets and an Apps Script project that in short does this:

我有一个5张谷歌电子表格和一个应用程序脚本项目,简而言之就是这样做的:


if (sheetName == "x") {
var range = sheet.getRange('C2:C23'); // Adjust the range as needed
var values = range.getDisplayValues();
return JSON.stringify(values);
} else if (sheetName == "y"){
var range = sheet.getRange('E2:E29'); // Adjust the range as needed
var values = range.getDisplayValues();
return JSON.stringify(values);
} else if (sheetName = "z"){//wrong operator
var range = sheet.getRange('E2:E29'); // Adjust the range as needed
var values = range.getDisplayValues();
return JSON.stringify(values);
}

When I call it for x, it successfully returns the correct array. Unfortunately, both for y and z it stops after the first 15 elements. Is there any workaround for this? Why does this happen?

当我为x调用它时,它成功地返回了正确的数组。不幸的是,对于y和z,它都在前15个元素之后停止。是否有解决此问题的方法?这一切为什么要发生?


I tried to call 'getValues' instead of 'getDisplayValues'.

我尝试调用‘getValues’而不是‘getDisplayValues’。


Also tried to concatenate smaller chunks with pagination like that:

还尝试将较小的块与分页连接在一起,如下所示:



var values = [];
var range = sheet.getRange('E2:E' + sheet.getLastRow()).getValues();
var chunkSize = 15; // Number of values to retrieve in each chunk

for (var i = 0; i < range.length; i += chunkSize) {
var chunk = range.slice(i, i + chunkSize);
values = values.concat(chunk);
}
return JSON.stringify(values);

However, nothing seems to work. Why does it work only for the x sheetName?

然而,似乎什么都没有奏效。为什么它只对x SheetName起作用?


更多回答

Welcome to Stack Overflow. Please add a minimal reproducible example. In this case, you should add a complete function, not only a snippet. Also, you should include some sample data and show what you have tried to debug the code. Note: There is a typo on the third if statment, sheetName = "z", instead of = you should use == as in the other if statement.

欢迎来到Stack Overflow。请添加一个最小的可重现的例子。在这种情况下,您应该添加一个完整的函数,而不仅仅是一个代码片段。此外,您还应该包括一些示例数据,并显示您尝试调试代码的内容。注意:第三个if语句中有一个拼写错误,sheetName=“z”,而不是=,您应该在另一个if语句中使用==as。

Do you really have three sheets named “x”, “y” & “z”?

你们真的有名为“x”、“y”和“z”的三张纸吗?

In your third section of your if statement, you’re not using a comparison you’re using an assignment you need to use ==

在if语句的第三部分中,您没有使用比较,而是使用了需要使用==的赋值

优秀答案推荐
更多回答

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