![](/img/trans.png)
[英]google apps script get range somehow not working what am i doing wrong?
[英]Google Apps Script throwing e-mail failure notification for getLastRow, what am I doing wrong?
我有以下Google Apps脚本:
function myFunction() {
/// VARIABLE DEFINITION
// Get Spreadsheets
var sursa = SpreadsheetApp.openByUrl("*"); // *=Using one of my DOCS URL here
var destinatie = SpreadsheetApp.openByUrl("*"); // *=Using one of my DOCS URL here
// Set Sheets
var foaie_calcul_sursa = sursa.getSheetByName("*"); // *=Using a valid sheet name here
var foaie_calcul_destinatie = destinatie.getSheetByName("*"); // *=Using a valid sheet name here
var foaie_calcul_email = destinatie.getSheetByName("*"); // *=Using a valid sheet name here
var eroare = "!!!EROARE";
// Get target last row
var ultimul_rand_destinatie = foaie_calcul_destinatie.getLastRow();
Logger.log('Ultimul rand destinatie este %s', ultimul_rand_destinatie);
//// STOP VARIABLE DEFINITION
之后,脚本继续执行我在图纸上执行的操作。
该脚本工作正常,但是我已安排它每天使用触发器运行。 问题是,无论是每天运行还是每天运行,我都会收到以下Google Apps脚本故障通知
TypeError:无法调用null的方法“ getLastRow”。 (第16行,文件“ X”)
也许我没有按我的方式调用getLastRow方法,考虑到脚本的正常运行,这可能是一个错误。
有人可以给我一些想法为什么会发生这种情况,或者我可以使用一些替代方法来阻止我每天收到的这封烦人的电子邮件吗?
谢谢,
工作getSheetByName("sheet name")
在getSheetByName("sheet name")
是错误的,或者是错误,或者您的代码示例未显示其他因素。
根据错误,此行:
var foaie_calcul_destinatie = destinatie.getSheetByName("*"); // *=Using a valid sheet name here
没有得到参考表。 foaie_calcul_destinatie
为null
。
如果代码没有打开电子表格,那么您应该从以下行得到错误信息:
var destinatie = SpreadsheetApp.openByUrl("*"); // *=Using one of my DOCS URL here
但这没有发生。
您提供的代码没有错,因此它可以是工作表的名称,也可以是某种错误。
检查工作表名称中是否有空格或大小写差异。
可能影响此问题的唯一代码行如下:
function myFunction() {
var destinatie = SpreadsheetApp.openByUrl("*"); // *=Using one of my DOCS URL here
var foaie_calcul_destinatie = destinatie.getSheetByName("*"); // *=Using a valid sheet name here
var ultimul_rand_destinatie = foaie_calcul_destinatie.getLastRow();
}
如果工作表的名称正确,则说明存在某种错误。 您的工作表名称中是否包含空格? 如果是这种情况,请尝试用下划线替换空格。 例如“ Data_Sheet”。
如果您没有发现任何错误,请将该问题报告给Google。 https://code.google.com/p/google-apps-script-issues/issues/list
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.