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

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

问题描述

如果B列从第6行开始已更改,我想在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.

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.

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

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