我为 Google 表格编写了三个单独的函数。每个都以学生的电子邮件地址 (firstname.lastnameXX@d155.org) 作为输入,其中 XX 代表学生的毕业年份,并返回三个信息之一。分别。
- 名
- 姓
- 班级(大一、大二、大三或大四)
我想创建一个插件,询问用户哪一列包含学生电子邮件地址列表,然后让它循环遍历该列,在每个学生电子邮件地址上运行每个函数,将数据分成单独的列。我对创建菜单项并为它们分配功能感到很自在。我觉得我需要一个很棒的 for 循环或三个。并且还需要构建一些逻辑和方法,让用户选择哪一列有电子邮件地址。下面是我的每个函数的代码。任何帮助将不胜感激!
//Takes a student's email address and returns their proper first name.
function FNAME(input) {
var length = input.length;
var shortened = input.substring(0, length-11);
var replaceSpace = shortened.replace('.', ' ');
var spacePlace = replaceSpace.indexOf(" ");
var fName = replaceSpace.charAt(0).toUpperCase() + replaceSpace.slice(1, spacePlace);
return fName;
}
//Takes a student's email address and returns their proper last name.
function LNAME(input) {
var length = input.length;
var shortened = input.substring(0, length-11);
var replaceSpace = shortened.replace('.', ' ');
var spacePlace = replaceSpace.indexOf(" ");
var lName = replaceSpace.charAt(spacePlace+1).toUpperCase() + replaceSpace.slice(spacePlace+2);
return lName;
}
//Takes a student's email address and returns their class.
function GLEVEL(input) {
var currentTime = new Date();
var length = input.length;
var shortened = input.substring(0, length-9);
var newLength = shortened.length;
var gyear = input.substring(newLength-2, newLength);
var year = currentTime.getYear();
var month = currentTime.getMonth();
if (year - gyear == 2000 && month <= 6) {
gyear = "Senior";
}
else if (year - gyear == 1999 && month >= 7) {
gyear = "Senior";
}
if (year - gyear == 1999 && month <= 6){
gyear = "Junior";
}
else if (year - gyear == 1998 && month >= 7) {
gyear = "Junior";
}
if (year - gyear == 1998 && month <= 6){
gyear = "Sophomore"
}
else if (year - gyear == 1997 && month >= 7) {
gyear = "Sophomore";
}
if (year - gyear == 1997 && month <= 6){
gyear = "Freshman";
}
else if (year - gyear == 1996 && month >= 7) {
gyear = "Freshman";
}
return gyear;
}