请帮我修复邮件合并问题,我已经附上了我正在获取的代码"正则表达式后的无效标志。 (第41行,文件"代码")" 这是我要导入数据的sample sheet,我想在消息正文中添加表格以及一些文本。
function DornmatSingle() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var dataRange = sheet.getRange("A2:AC2");
var data = dataRange.getValues();
for (i in data) {
var rowData = data[i];
var emailAddress = rowData[28];
var submiterEmail = rowData[1];
var ProjectName = rowData[2];
var SrDesign = "Sr. Design Architect Services";
var PerHourRate = rowData[4];
var NumberOfHours = rowData[5];
var TotalRate = rowData[6];
var Contact = "Contact Centre Expert";
var PerHourRate2 = rowData[8];
var NumberOfHours2 = rowData[9];
var NTotalRate2 = rowData[10];
var NJrDesign = "Jr. Design Architect";
var PerHourRate3 = rowData[12];
var NumberOfHours3 = rowData[13];
var TotalRate3 = rowData[14];
var Outsourced = "Outsourced Technical Support Resource";
var PerHourRate4 = rowData[16];
var NumberOfHours4 = rowData[17];
var TotalRate4 = rowData[18];
var Supplier = "Supplier Management";
var PerHourRate5 = rowData[20];
var NumberOfHours5 = rowData[21];
var TotalRate5 = rowData[22];
var Project = "Project Management & Execution";
var PerHourRate6 = rowData[24];
var NumberOfHours6 = rowData[25];
var TotalRate6 = rowData[26];
var UserAccount = rowData[28];
var GrandTotalRate = rowData[27];
var subject = 'Technology Charges for '+ProjectName+'';
var message = <table border="1" align="center" cellpadding="5" cellspacing="0" style="font-family:Verdana; fontsize=9px"><tbody><tr><td style="background-color:#a4fff9;">Sr.No.</td><td style="background-color:#a4fff9;">Cost Element</td><td style="background-color:#a4fff9;">Unit Price</td><td style="background-color:#a4fff9;">UOM
</td><td style="background-color:#a4fff9;">Quantity</td><td style="background-color:#a4fff9;">Total Cost</td></tr><tr><td>1</td><td>Sr. Design Architect Services</td><td> +PerHourRate+ </td><td>Hrs </td><td> +NumberOfHours+ </td><td>+TotalRate+</td></tr></tr><td>2</td><td>Jr. Design Architect</td><td> +PerHourRate3+ </td><td>Hrs </td><td> +NumberOfHours3+ </td><td>+TotalRate3+</td></tr></tr><td>3</td><td>Contact Centre Expert</td><td> +PerHourRate2+ </td><td>Hrs </td><td> +NumberOfHours2+ </td><td> +NTotalRate2+ </td></tbody></table>
MailApp.sendEmail({
to: emailAddress,
subject: subject,
htmlBody: message,
});
}}
&#13;
答案 0 :(得分:1)
错误是因为您没有将变量message
的内容设置为字符串。如下或以合适的方式定义消息变量,使其仍然是一个字符串:
var message = '<table border="1" align="center" cellpadding="5" cellspacing="0" style="font-family:Verdana; fontsize=9px"><tbody><tr><td style="background-color:#a4fff9;">Sr.No.</td><td style="background-color:#a4fff9;">Cost Element</td><td style="background-color:#a4fff9;">Unit Price</td><td style="background-color:#a4fff9;">UOM'+
'</td><td style="background-color:#a4fff9;">Quantity</td><td style="background-color:#a4fff9;">Total Cost</td></tr><tr><td>1</td><td>Sr. Design Architect Services</td><td>' +PerHourRate+ '</td><td>Hrs </td><td>' +NumberOfHours+ '</td><td>+TotalRate+</td></tr></tr><td>2</td><td>Jr. Design Architect</td><td>' +PerHourRate3+ '</td><td>Hrs </td><td> +NumberOfHours3+ </td><td>'+TotalRate3+'</td></tr></tr><td>3</td><td>Contact Centre Expert</td><td>' +PerHourRate2+ '</td><td>Hrs </td><td>' +NumberOfHours2+ '</td><td>' +NTotalRate2+ '</td></tbody></table>'