我目前正在尝试使用您可以选择名称的表单,并根据该选项从单独的电子表格中返回值。问题是if和else if是否给了我奇怪的结果。前3个工作正常但第4个返回第一个if(jillian)的值,cali返回ashley的值。我已经找了一个开放式支架或任何可以指向正确方向而没有运气的东西。下面是我正在使用的脚本。
function emailInfoRequired() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
var data = sheet.getRange(sheet.getLastRow(), 1, 1, sheet.getLastColumn()).getValues();
var player = data[0][1].trim();
var email = data[0][2].trim();
var jillianachoice = /^[Jillian A].*$/i;
var trinitybchoice = /^[Trinity B].*$/i;
var emmabchoice = /^[Emma B].*$/i;
var ashleycchoice = /^[Ashley C].*$/i;
var caliechoice = /^[Cali E].*$/i;
var chloehchoice = /^[Chloe H].*$/i;
var sierrajchoice = /^[Sierra J].*$/i;
var kirakchoice = /^[Kira K].*$/i;
var skylarkchoice = /^[Skylar K].*$/i;
var alainalchoice = /^[Alaina L].*$/i;
var jadynnchoice = /^[Jadyn N].*$/i;
var kaedingrchoice = /^[Kaeding R].*$/i;
var schuylerrchoice = /^[Schuyler R].*$/i;
var taylorschoice = /^[Taylor S].*$/i;
var bellaschoice = /^[Bella S].*$/i;
var elizabethschoice = /^[Elizabeth S].*$/i;
var abbywchoice = /^[Abby W].*$/i;
var ss = SpreadsheetApp.openById("spreadsheetID");//other spreadsheet with the values
var sheet1 = ss.getSheetByName("Form Responses 1");
var subject = "U13G Neon Player Stats Averages";
var recipients = email;
var Header = sheet1.getRange('C1:F1').getValues();
var jilliana = sheet1.getRange('C2:F2').getValues();// define your range here
var trinityb = sheet1.getRange('C3:F3').getValues();// define your range here
var emmab = sheet1.getRange('C4:F4').getValues();// define your range here
var ashleyc = sheet1.getRange('C5:F5').getValues();// define your range here
var calie = sheet1.getRange('C6:F6').getValues();// define your range here
var chloeh = sheet1.getRange('C7:F7').getValues();// define your range here
var sierraj = sheet1.getRange('C8:F8').getValues();// define your range here
var kirak = sheet1.getRange('C9:F9').getValues();// define your range here
var skylark = sheet1.getRange('C10:F10').getValues();// define your range here
var alainal = sheet1.getRange('C11:F11').getValues();// define your range here
var jadynn = sheet1.getRange('C12:F12').getValues();// define your range here
var kaedingr = sheet1.getRange('C13:F13').getValues();// define your range here
var schuylerr = sheet1.getRange('C14:F14').getValues();// define your range here
var taylors = sheet1.getRange('C15:F15').getValues();// define your range here
var bellas = sheet1.getRange('C16:F16').getValues();// define your range here
var elizabeths = sheet1.getRange('C17:F17').getValues();// define your range here
var abbyw = sheet1.getRange('C18:F18').getValues();// define your range here
if (jillianachoice(player)) {
var message = '<HTML><BODY><p>Jillian A</p><table style="border-collapse:collapse;" border = 1><tr>';// change eventually the color here
for (var row1 = 0;row1<Header.length;++row1){
for(var col1 = 0;col1<Header[0].length;++col1){
message += '<th style="height:100%; width:5%">'+Header[row1][col1]+'</th>';
}
message += '</tr><tr>';
}
for (var row2 = 0;row2<jilliana.length;++row2){
for(var col2 = 0;col2<jilliana[0].length;++col2){
message += '<th style="height:100%; width:5%">'+jilliana[row2][col2]+'</th>';
}
}
message += '</tr></table></body></HTML>';
MailApp.sendEmail(recipients, subject, "", {htmlBody: message});
} else if (trinitybchoice(player)) {
var message1 = '<HTML><BODY><p>Trinity B</p><table style="border-collapse:collapse;" border = 1><tr>';// change eventually the color here
for (var row3 = 0;row3<Header.length;++row3){
for(var col3 = 0;col3<Header[0].length;++col3){
message1 += '<th style="height:100%; width:5%">'+Header[row3][col3]+'</th>';
}
message1 += '</tr><tr>';
}
for (var row4 = 0;row4<trinityb.length;++row4){
for(var col4 = 0;col4<trinityb[0].length;++col4){
message1 += '<th style="height:100%; width:5%">'+trinityb[row4][col4]+'</th>';
}
}
message1 += '</tr></table></body></HTML>';
MailApp.sendEmail(recipients, subject, "", {htmlBody: message1});
} else if (emmabchoice(player)) {
var message2 = '<HTML><BODY><p>Emma B</p><table style="border-collapse:collapse;" border = 1><tr>';// change eventually the color here
for (var row5 = 0;row5<Header.length;++row5){
for(var col5 = 0;col5<Header[0].length;++col5){
message2 += '<th style="height:100%; width:5%">'+Header[row5][col5]+'</th>';
}
message2 += '</tr><tr>';
}
for (var row6 = 0;row6<emmab.length;++row6){
for(var col6 = 0;col6<emmab[0].length;++col6){
message2 += '<th style="height:100%; width:5%">'+emmab[row6][col6]+'</th>';
}
}
message2 += '</tr></table></body></HTML>';
MailApp.sendEmail(recipients, subject, "", {htmlBody: message2});
} else if (ashleycchoice(player)) {
var message3 = '<HTML><BODY><p>Ashley C</p><table style="border-collapse:collapse;" border = 1><tr>';// change eventually the color here
for(var row7 = 0;row7<Header.length;++row7){
for(var col7 = 0;col7<Header[0].length;++col7){
message3 += '<th style="height:100%; width:5%">'+Header[row7][col7]+'</th>';
}
message3 += '</tr><tr>';
}
for(var row8 = 1;row8<ashleyc.length;++row8){
for(var col8 = 1;col8<ashleyc[0].length;++col8){
message3 += '<th style="height:100%; width:5%">'+ashleyc[row8][col8]+'</th>';
}
}
message3 += '</tr></table></body></HTML>';
MailApp.sendEmail(recipients, subject, "", {htmlBody: message3});
} else if (caliechoice(player)) {
var message4 = '<HTML><BODY><p>Cali E</p><table style="border-collapse:collapse;" border = 1><tr>';// change eventually the color here
for (var row9 = 0;row9<Header.length;++row9){
for(var col9 = 0;col9<Header[0].length;++col9){
message4 += '<th style="height:100%; width:5%">'+Header[row9][col9]+'</th>';
}
message4 += '</tr><tr>';
}
for (var row10 = 0;row10<calie.length;++row10){
for(var col10 = 0;col10<calie[0].length;++col10){
message4 += '<th style="height:100%; width:5%">'+calie[row10][col10]+'</th>';
}
}
message4 += '</tr></table></body></HTML>';
MailApp.sendEmail(recipients, subject, "", {htmlBody: message4}); //Plus 12 more players
答案 0 :(得分:0)
好的..我发现了问题。由于变量使用正则表达式,例如:
var jillianachoice = /^[Jillian A].*$/i;
。*告诉它匹配括号中的任何内容,而i告诉它忽略大小写。对于我想要实现的目标应该是:
var jillianachoice = /^Jillian A$/;
这将采用文字而不是匹配任何字母。