发送电子邮件 - 保留单元格格式
Send Email - Keep Cell Formatting
我有一个 google spreadsheet,它发送包含在从另一个 sheet 查询和连接的列中的学生信息。查询信息以回车returns分隔。然后将此列通过电子邮件发送给由公式触发的家庭,该公式计算单元格中应包含多少个returns。
那部分我已经在 sheet 中处理过了。我需要有关通过电子邮件发送列和维护单元格格式的帮助。我已经能够使用下面的代码做到这一点,但它会在每封电子邮件中发送 D 列中的所有数据。我需要它只发送位于电子邮件相应行中的内容。
我认为给我带来麻烦的主要代码部分如下:
var OriginalString = SpreadsheetApp.getActive().getRange("D2:D").getValues();
var NewString = OriginalString.toString().replace(/\n/g, '<br>');
如有任何帮助,我们将不胜感激!
function SendEmail3() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var startrow = 2;
var lastRow = ss.getLastRow();
var lastCol = 10;
var range = ss.getRange(2, 1, lastRow, lastCol);
var data = range.getValues();
for (var i = 0; i < data.length; i++) {
var row = data[i];
var AccountName = row[0];
var email = row[1];
var Parent = row[2];
var Consent = row[4];
var StudentData = row[3];
var CarriageReturns = row[6];
var Trigger = row[7];
var emailSent = row[8];
var subject = "Your Application";
var OriginalString = SpreadsheetApp.getActive().getRange("D2:D").getValues();
var NewString = OriginalString.toString().replace(/\n/g, '<br>');
var message = "<HTML><BODY><font size=4>" +
"<P>" + "Hello " + Parent + ','
+"<BR>
+"<BR>" + NewString + "<BR>"
+"</HTML></BODY>";
var recipientsTo = email;
if (AccountName.length > 0 && Trigger >= CarriageReturns && emailSent != 'EMAIL_SENT') {
MailApp.sendEmail({
subject: subject,
to: recipientsTo,
htmlBody: message
});
ss.getRange(startrow + i, 9).setValue('EMAIL_SENT');
}
}
}
这是您要找的吗?
我将其设置为您可以在无模式对话框中查看消息,而不是发送电子邮件。
function SendEmail3() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var startrow = 2;
var lastRow = ss.getLastRow();
var lastCol = 10;
var range = ss.getRange(2, 1, lastRow, lastCol);
var data = range.getValues();
var html='';//Remove
for (var i = 0; i < data.length; i++) {
var row = data[i];
var AccountName = row[0];
var email = row[1];
var Parent = row[2];
var Consent = row[4];
var StudentData = row[3];
var CarriageReturns = row[6];
var Trigger = row[7];
var emailSent = row[8];
var subject = "Your Application";
var NewString = StudentData.split('\n').join('<br />');
//var message = "<HTML><BODY><font size=4>" + "<P>" + "Hello " + Parent + ',' + "<BR>" +"<BR>" + NewString + "<BR>" +"</HTML></BODY>";
var message=Utilities.formatString('<HTML><BODY><font size=4><P>Hello %s,<BR><BR>%s<BR></HTML></BODY>', Parent,NewString);
var recipientsTo = email;
if (AccountName.length > 0 && Trigger >= CarriageReturns && emailSent != 'EMAIL_SENT') {
//MailApp.sendEmail({subject: subject,to: recipientsTo,htmlBody: message});
html+=Utilities.formatString('%s- %s',i+1,message);//Remove
//ss.getRange(startrow + i, 9).setValue('EMAIL_SENT');
}
}
var userInterface=HtmlService.createHtmlOutput(html);//Remove
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Email Message');//Remove
}
我有一个 google spreadsheet,它发送包含在从另一个 sheet 查询和连接的列中的学生信息。查询信息以回车returns分隔。然后将此列通过电子邮件发送给由公式触发的家庭,该公式计算单元格中应包含多少个returns。
那部分我已经在 sheet 中处理过了。我需要有关通过电子邮件发送列和维护单元格格式的帮助。我已经能够使用下面的代码做到这一点,但它会在每封电子邮件中发送 D 列中的所有数据。我需要它只发送位于电子邮件相应行中的内容。
我认为给我带来麻烦的主要代码部分如下:
var OriginalString = SpreadsheetApp.getActive().getRange("D2:D").getValues();
var NewString = OriginalString.toString().replace(/\n/g, '<br>');
如有任何帮助,我们将不胜感激!
function SendEmail3() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var startrow = 2;
var lastRow = ss.getLastRow();
var lastCol = 10;
var range = ss.getRange(2, 1, lastRow, lastCol);
var data = range.getValues();
for (var i = 0; i < data.length; i++) {
var row = data[i];
var AccountName = row[0];
var email = row[1];
var Parent = row[2];
var Consent = row[4];
var StudentData = row[3];
var CarriageReturns = row[6];
var Trigger = row[7];
var emailSent = row[8];
var subject = "Your Application";
var OriginalString = SpreadsheetApp.getActive().getRange("D2:D").getValues();
var NewString = OriginalString.toString().replace(/\n/g, '<br>');
var message = "<HTML><BODY><font size=4>" +
"<P>" + "Hello " + Parent + ','
+"<BR>
+"<BR>" + NewString + "<BR>"
+"</HTML></BODY>";
var recipientsTo = email;
if (AccountName.length > 0 && Trigger >= CarriageReturns && emailSent != 'EMAIL_SENT') {
MailApp.sendEmail({
subject: subject,
to: recipientsTo,
htmlBody: message
});
ss.getRange(startrow + i, 9).setValue('EMAIL_SENT');
}
}
}
这是您要找的吗?
我将其设置为您可以在无模式对话框中查看消息,而不是发送电子邮件。
function SendEmail3() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet3');
var startrow = 2;
var lastRow = ss.getLastRow();
var lastCol = 10;
var range = ss.getRange(2, 1, lastRow, lastCol);
var data = range.getValues();
var html='';//Remove
for (var i = 0; i < data.length; i++) {
var row = data[i];
var AccountName = row[0];
var email = row[1];
var Parent = row[2];
var Consent = row[4];
var StudentData = row[3];
var CarriageReturns = row[6];
var Trigger = row[7];
var emailSent = row[8];
var subject = "Your Application";
var NewString = StudentData.split('\n').join('<br />');
//var message = "<HTML><BODY><font size=4>" + "<P>" + "Hello " + Parent + ',' + "<BR>" +"<BR>" + NewString + "<BR>" +"</HTML></BODY>";
var message=Utilities.formatString('<HTML><BODY><font size=4><P>Hello %s,<BR><BR>%s<BR></HTML></BODY>', Parent,NewString);
var recipientsTo = email;
if (AccountName.length > 0 && Trigger >= CarriageReturns && emailSent != 'EMAIL_SENT') {
//MailApp.sendEmail({subject: subject,to: recipientsTo,htmlBody: message});
html+=Utilities.formatString('%s- %s',i+1,message);//Remove
//ss.getRange(startrow + i, 9).setValue('EMAIL_SENT');
}
}
var userInterface=HtmlService.createHtmlOutput(html);//Remove
SpreadsheetApp.getUi().showModelessDialog(userInterface, 'Email Message');//Remove
}