在我的代码中发现此错误TypeError:无法读取null的属性"getLastRow"(第5行,文件“代码") [英] find this error in my code TypeError: Cannot read property 'getLastRow' of null (line 5, file "Code")

查看:72
本文介绍了在我的代码中发现此错误TypeError:无法读取null的属性"getLastRow"(第5行,文件“代码")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

返回 null .换句话说,您的电子表格没有名为 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.

注意:

下图显示了电子表格名称表格名称

相关

这篇关于在我的代码中发现此错误TypeError:无法读取null的属性"getLastRow"(第5行,文件“代码")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆