如何解决谷歌应用程序脚本错误:“TypeError:无法调用 null 的方法“getRange”。(第 16 行,文件“代码”)”在调试以下脚本时:
function getEmails_(q) {
var emails = [];
var threads = GmailApp.search(q);
for (var i in threads) {
var msgs = threads[i].getMessages();
for (var j in msgs) {
emails.push([msgs[j].getBody().replace(/<.*?>/g, '\n')
.replace(/^\s*\n/gm, '').replace(/^\s*/gm, '').replace(/\s*\n/gm, '\n')
]);
}
}
return emails;
}
function appendData_(sheet, array2d) {
sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);
}
function saveEmails() {
var array2d = getEmails_("Still looking for Python Programming help");
if (array2d) {
appendData_(SpreadsheetApp.getActiveSheet(), array2d);
}
}