gpt4 book ai didi

javascript - Google 脚本左侧分配无效

转载 作者:行者123 更新时间:2023-12-03 12:06:35 27 4
gpt4 key购买 nike

好的,我有这个代码。抱歉,我不知道问题出在哪里,所以我把它全部粘贴了。它说:左侧赋值无效。 (第 1 行,文件“代码”)。我知道问题不可能出现在第一行,但不知道问题出在哪里。

function send(sheet, email, row){
var tmp = GmailApp.getAliases();
var alias = tmp[0];

var subject = "Thank you for signing up for "+ sheet.getSheetName()+ "!";
var body = "Hello "+ sheet.getRange(row,3).getValue() + " " + sheet.getRange(row,4).getValue() + "," + '\n'+'\n';
var temp = 2;
var bool = "TRUE";
while (bool == "TRUE"){
if (sheet.getRange(temp,11).getValue() != ''){
body += '\n' + sheet.getRange(temp,11);
temp += 1;
}
if (sheet.getRange(temp + 1,11).getValue() != '')
body += '\n' + body += '\n' + sheet.getRange(temp + 1,11);
else {bool = "FALSE"}
}

Logger.log(body);

if ( sheet.getRange('L2').getValue() != ""){
var html = sheet.getRange('L2').getValue(); // Place HTML code here
try {
GmailApp.sendEmail(email, subject, body, {'from': alias, 'htmlbody': html});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
var me = Session.getActiveUser().getEmail();
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
else{
try {
GmailApp.sendEmail(email, subject, body, {'from': alias});
sheet.getRange(row, 9).setBackground("green");
sheet.getRange(row, 9).setValue("Yes");
sheet.getRange("J2").setValue(row - 2);
} catch (e) {
MailApp.sendEmail(me, "Autoreply error", "There was a problem sending an email to: " + email +".");
}
}
}

function main(){
var ss = SpreadsheetApp.openById("1a2xvZ6hx69hst0CoLnCc8V5Igi-V5_HaNm6GTpEU8B4"); // Unique ID for the 'Responses' spreadsheet
var sheet = ss.getActiveSheet();

if ( sheet.getRange('J2').getValue() == "" ){
sheet.getRange('I1').setValue("Sent"); // Initialize labels
sheet.getRange('J1').setValue("Count");
sheet.getRange('K1').setValue("Email body");
sheet.getRange('L1').setValue("HTML body");
var row = 2;
} else {
var row = sheet.getRange("J2").getValue() + 2;
}
while ( (sheet.getRange(row,9).getValue() != '') && (sheet.getRange(row,2).getValue() != '')) {
var email = sheet.getRange(row, 2).getValue();
send(sheet, email, row);
row += 1;
}
}

最佳答案

您不能编写这样的行:(同一语句中的 2 x +=)

body += '\n' + body += '\n' + sheet.getRange(temp + 1,11); // this throws the error

我建议使用这样的中间变量:

 var xxx = '\n' + sheet.getRange(temp + 1,11);
body+= '\n'+ body + xxx ;

如果这真的是你想做的事...但对我来说这似乎很奇怪...

不应该是这样的吗:body+= '\n'+sheet.getRange(temp + 1,11);

关于javascript - Google 脚本左侧分配无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25164793/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com