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

点点圈 提交于 2021-02-15 07:48:08

问题


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)
}
    
}

回答1:


The error occurs because

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

returns null. In other words, your spreadsheet hasn't a sheet named prices.

Double check if the argument of the above code line is correct as well is your spreadsheet has the required structure and content.

NOTES:

The following image shows where goes the spreadsheet name and were goes the sheet name

Related

  • TypeError: Cannot read property 'pair' of undefined


来源:https://stackoverflow.com/questions/63046368/find-this-error-in-my-code-typeerror-cannot-read-property-getlastrow-of-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!