谷歌电子表格“无法调用方法“getRange"的“空" [英] Google spreadsheet "Cannot call method "getRange" of null"

查看:36
本文介绍了谷歌电子表格“无法调用方法“getRange"的“空"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果从第 6 行开始,B 列的每一行都发生了变化,我想在 A 列中生成一个唯一 ID.使用 1 到 X 之间的数字作为 ID 就足够了,但是在移动 de row 后它应该不会改变.但是我不断收到错误无法调用 null 的方法getRange"."

I'd like to generate a unique ID in column A if column B has changed in every row from the 6th. It would be enough to use a number from 1 to X as ID but it should no change after moving de row. Yet I'm getting an error continuously "Cannot call method "getRange" of null."

function onEdit() {
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('ScriptTest');
 var column0 = sheet.getRange(6, 2, sheet.getLastRow()-6, 1);
 var oValues = column0.getValues();

 if (oValues[sheet.getLastRow()][0] == '') {
   sheet.getRange(sheet.getLastRow(), 1, 1, 1).setValue(ContentService.createTextOutput(sheet.getLastRow()-6));
 }  
}

推荐答案

当您在处理像这里这样的工作表对象时出现错误时,您可以通过它所提取的缺失值类型轻松识别来源.

When you have errors with working with sheet objects like here you can easily identify the source by the kind of missing value it's pulling from.

undefined 是未定义的,这意味着工作表的变量从未被赋予值或已设置为未定义.

undefined is undefined, meaning the variable for the sheet was never given a value or has been set to undefined.

当您尝试通过不存在的名称获取选项卡时,变量将设置为 null,如此处的情况.

the variable is set to null when you are trying to get a tab by a name that doesn't exist, as is the case here.

其他任何情况都可能意味着您访问了错误的变量.

Anything else probably means you are accessing the wrong variable.

这篇关于谷歌电子表格“无法调用方法“getRange"的“空"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆