无法调用null的方法“ getRange”。 (第20行,文件“代码”)

时间:2019-02-11 15:47:16

标签: google-apps-script google-sheets

TypeError:无法调用null的方法“ getRange”。 (第20行,文件“代码”) 我的脚本正在按期望的方式运行,但是我继续遇到上述错误。该脚本有一个触发器,可以在表单完成时运行,它会移动数据,然后返回上述错误。 Here is the sheet

第20行是

// I'm hardcoding it as a string, because I don't have your api to call.
let xmlString = '<?xml version="1.0" encoding="utf-8"?> <string xmlns="url">[{"Ref":"IHR1900299","Unvan":"max"},{"Ref":"IHR1900298","Unvan":"max2"}] </string>';

let jsonString = xmlString.match(/\[.*\]/);
let json = JSON.parse(jsonString);
    
console.log(json)
console.log(json[0].Ref)

我检查了工作表名称并进行了调整,但似乎缺少一些内容。

    var data = sourceSpreadSheetSheetID.getRange(2, 1,sourceSpreadSheetSheetID.getLastRow()-1, sourceSpreadSheetSheetID.getLastColumn()).getValues();

我希望该脚本能够正确运行

1 个答案:

答案 0 :(得分:1)

所以代码看起来像应该运行,因为您得到的错误是关于sourceSpreadSheetSheetID null值,所以当我检查您发布的电子表格时,我注意到工作表您称为“ HallPass”实际上称为“ Hall_Pass ”。在您的代码中,没有传递变量HallPass,而是给它提供了一个字符串"HallPass"。这就是问题所在。

var ss = SpreadsheetApp.openById('1B93n7wQ8rosmcaqlpgD9FoL1KWfbXALrror7t6r5K2M'); //Need ID from Form response sheet
var sourceSpreadSheetSheetID = ss.getSheetByName(HallPass); //Sheet name was incorrect.
// Did you mean to leave out the Quotations to refer to the variable above?
var sourceSpreadSheetSheetID1 = ss.getSheetByName(CheckOut);
var sourceSpreadSheetSheetID2 = ss.getSheetByName(CheckIn);
相关问题