Domanda

Continuo a ricevere questo errore quando provo ed eseguire questo script. E ha funzionato bene per diversi giorni. E 'in un foglio di calcolo di Google Docs.

TypeError: Impossibile chiamata al metodo "getRange" di null. (Riga 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"));
  }
}

C'è qualcosa che può vedere che causerebbe questo errore?

È stato utile?

Soluzione

Hai controllato il valore di ritorno di ss.getSheetByName("PO Form"). E 'più probabile null. Hai anche un livello di classe namedss e il metodo variabili variabile denominata ss pure. Questo tipo di ombreggiamento può portare a problemi se non siete molto attenti.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top