[英]GAS: Error on SpreadSheet for mailing
Now I'm trying to send email by using lists on the spreadsheet with Google Apps Script. 现在,我尝试通过使用Google Apps脚本在电子表格上使用列表来发送电子邮件。
I coded (well, just copy and paste sample program on the book actually) like following, but an error occurred that is "TypeError: Cannot call method "getLastRow" of null." 我按照以下方式进行编码(实际上,只需将示例程序复制并粘贴到书上),但是发生了一个错误,即“ TypeError:无法调用null的方法“ getLastRow”。
function sendMail() {
var mySS = SpreadsheetApp.getActiveSpreadsheet();
var mailSheet = mySS.getSheetByName("メール");
var addSheet = mySS.getSheetByName("住所録");
var endRow = addSheet.getLastRow();
var mySubject = mailSheet.getRange("C2").getValue();
for (i = 2; i <= endRow; i++ ) {
if (addSheet.getRange(i, 3).getValue()) {
var myBody = addSheet.getRange(i, 1)
.getValue() + "様¥n¥n";
myBody = myBody + mailSheet.getRange("C3").getValue();
var mailTo = addSheet.getRange(i, 2).getValue();
GmailApp.sendEmail(mailTo, mySubject, myBody);
}
}
Browser.msgBox("メール送信しました");
}
sorry for some include Japanese, but I created 2 sheets named "メール" and "住所録” then input data. 抱歉,其中一些日语,但我创建了2个工作表,分别为“メール”和“住所录”,然后输入了数据。
Could someone help me to fix this? 有人可以帮我解决这个问题吗?
You spreadsheet does not have a sheet named "住所録". 您的电子表格没有名为“住所录”的工作表。
The method getSheetByName does not throw an error if the sheet isn't found, it just returns null
如果找不到工作表,则getSheetByName方法不会引发错误,它只会返回
null
I think the problem is the fact that your sheet names are in Japanese. 我认为问题在于您的工作表名称为日语。 The encoding used by the script in Google's servers will be different.
Google的服务器中脚本使用的编码会有所不同。 Therefore, it will not return any sheet.
因此,它将不返回任何纸张。 Rename your sheets to English and it will work
将工作表重命名为英语,它将起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.