gpt4 book ai didi

GAS error: TypeError: Cannot read property 'getLastRow' of null (line 4, file "Code2")(GAS错误:TypeError:无法读取空值的属性‘getLastRow’(第4行,文件“Code2”))

转载 作者:bug小助手 更新时间:2023-10-25 23:19:53 26 4
gpt4 key购买 nike



The GAS code bellow outputs an error while running the function fromPS: TypeError: Cannot read property 'getLastRow' of null (line 4, file "Code2")

从ps:TypeError:Cannot Read属性‘getLastRow’of NULL(第4行,文件“Code2”)运行函数时,下面的GAS代码输出错误



I cannot see what is wrong in this code. I have tried to use the property getSheetByName instead of getSheets, but both the error still the same.

我看不出这段代码有什么问题。我尝试使用属性getSheetByName而不是getSheets,但两者的错误仍然相同。



What do you see that I do not?

你看到了什么我看不到的?



Thank you!

谢谢!



code:

代码:



function toSpreadsheet(text2write)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; //getSheetByName("HIL_APP_Log");
var lastRow = sheet.getLastRow();

for (var i = 1; i < lastRow; i++)
{
sheet.getRange(i+1, 8, 1).setValue(text2write)
}
return "myreturn"
}

function fromPS() //fromPS(params)
{
params = "fromGAS"
Logger.log(params)
var rtn = toSpreadsheet(params)
return rtn
}

更多回答

Code is solid. I ran it on my end and it works fine. Try it in another google sheet and see if it works. If it doesn't, restart the computer and try again.

代码是可靠的。我用我的一端运行它,它工作得很好。在另一个谷歌表格中尝试一下,看看它是否有效。如果没有,请重新启动计算机,然后重试。

Is your script bound to a sheet correctly? Did you access it through Tools > Script Editor? Could you share what your spreadsheet looks like?

您的脚本是否正确绑定到工作表?您是通过工具>脚本编辑器访问的吗?你能分享一下你的电子表格是什么样子的吗?

优秀答案推荐

Cannot read property 'getLastRow' means that sheet.getLastRow() does not exist



The reason is sheet is defined wrongly.

原因是板材定义错误。



For example if you specify var sheet = ss.getSheets()[1];

例如,如果指定var Sheet=ss.getSheets()[1];



while your spreadsheet has less than 2 sheets or

当您的电子表格包含的工作表少于2个或



var sheet = ss.getSheets().getSheetByName("WRONG NAME");,

Var Sheet=ss.getSheets().getSheetByName(“名称错误”);,



which commonly occurs if you do not respect case sensitivity.

如果您不区分大小写,则通常会发生这种情况。



That code worked fine before. For an unknown reason, getActiveSpreadsheet() was not finding any active spreadsheet, then it was returning null.

这个代码以前运行得很好。由于未知原因,getActiveSpreadSheet()找不到任何活动的电子表格,然后返回空。



To fix that I had to create another Script project. Now the same code runs fine.

为了解决这个问题,我不得不创建另一个脚本项目。现在,相同的代码运行得很好。



In my case, where I had similar error. I changed

在我的例子中,我也犯了类似的错误。我变了


var sheet = SpreadsheetApp.getActive().getSheetByName("Name of spreadsheet");

for


var sheet = SpreadsheetApp.getActiveSheet();

And now works !

现在成功了!


更多回答

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