TypeError:无法调用方法“getRange”的空值。 (第0行) [英] TypeError: Cannot call method "getRange" of null. (line 0)
问题描述
当我尝试运行此脚本时,我不断收到此错误。它已经运行好几天了。它位于Google Docs Spreadsheet中。
TypeError:无法调用null方法getRange。 (第0行)
ss = SpreadsheetApp.getActiveSpreadsheet();
函数onOpen(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [{name:New PO,functionName:NewPO}];
ss.addMenu(New PO,menuEntries);
}
函数NewPO(){
SpreadsheetApp.getActiveSheet()。insertRowsBefore(1,6);
//相应地调整这个范围,这些单元格将被
//复制。格式为getRange(startRow,startCol,numRows,numCols)
ss.getSheetByName(PO Form)。getRange(1,1,6,8)
.copyTo(SpreadsheetApp.getActiveSheet()。getRange (1,1,6,8));
}
function onEdit(e){
var ss = e.source.getActiveSheet();
var r = e.source.getActiveRange();
// 1是A,2是B,... 8是H
if(r.getColumn()== 8&& r.getValue()==x){
r.setValue(Utilities.formatDate(new Date(),GMT,yyyy-MM-dd));
$ / code>
有什么可以看到的会导致此错误?
你检查了 ss.getSheetByName(PO Form )
。这很可能是 null
。您还有一个名为 ss
的类级变量和名为 ss
的方法变量。这种阴影可能会导致问题,如果你不是很小心。
I keep getting this error when I try and run this script. It has run just fine for several days. It is in a Google Docs Spreadsheet.
TypeError: Cannot call method "getRange" of null. (line 0)
ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "New PO", functionName: "NewPO"}];
ss.addMenu("New PO", menuEntries);
}
function NewPO() {
SpreadsheetApp.getActiveSheet().insertRowsBefore(1,6);
// Adjust this range accordingly, these are the cells that will be
// copied. Format is getRange(startRow, startCol, numRows, numCols)
ss.getSheetByName("PO Form").getRange(1, 1, 6, 8)
.copyTo(SpreadsheetApp.getActiveSheet().getRange(1, 1, 6, 8));
}
function onEdit(e) {
var ss = e.source.getActiveSheet();
var r = e.source.getActiveRange();
// 1 is A, 2 is B, ... 8 is H
if (r.getColumn() == 8 && r.getValue() == "x") {
r.setValue(Utilities.formatDate(new Date(), "GMT", "yyyy-MM-dd"));
}
}
Is there anything you can see that would cause this error?
Have you checked the return value of ss.getSheetByName("PO Form")
. It is most likely null
. You also have a class level variable namedss
and method variables named ss
as well. This sort of shadowing can lead to problems if you're not very careful.
这篇关于TypeError:无法调用方法“getRange”的空值。 (第0行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!