TypeError:Não é possível chamar o método "getRange" nulo.(linha 0)
-
25-09-2019 - |
Pergunta
Eu continuo recebendo esse erro quando tento executar este script.Ele foi executado apenas multa por vários dias.Ele está em um Google Docs Planilha.
TypeError:Não é possível chamar o método "getRange" nulo.(linha 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"));
}
}
Há algo que você pode ver o que poderia causar este erro?
Solução
Você já verificou o valor de retorno de ss.getSheetByName("PO Form")
.É mais provável null
.Você também tem um nível de classe de variável chamadass
e método de variáveis denominado ss
bem.Este tipo de sombreamento pode levar a problemas se você não for muito cuidadoso.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow