find this error in my code TypeError: Cannot read property 'getLastRow' of null (line 5, file "Code")

find this error in my code TypeError: Cannot read property 'getLastRow' of null (line 5, file "Code")

function prices() {

  var scraperSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("prices")
  
  var lrow = scraperSheet.getLastRow();
  
  for (var i=2;i<=lrow;i++)
  {
    
    var regEx = /<span id="priceblock_dealprice.*<\/span>/gi
  
    var getContent = UrlFetchApp.fetch("https://www.amazon.in/"+scraperSheet.getRange(i,1).getValue()).getContentText().trim();
    var price = getContent.match(regEx)
    price = price[0];
    price = price.replace('<span id="priceblock_dealprice" class="a-size-medium a-color-price priceBlockDealPriceString">',"")
    .replace('</span>',"")
    scraperSheet.getRange(i,3).setValue(price)
}
    
}

错误发生是因为

SpreadsheetApp.getActiveSpreadsheet().getSheetByName("prices")

returnsnull。换句话说,您的价差 sheet 没有名为 prices 的 sheet。

仔细检查以上代码行的参数是否正确以及您的传播sheet是否具有所需的结构和内容。

备注:

下图显示了 spreadsheet namesheet name

相关