我使用脚本自动插入日期和用户名来填充字符串。几个人填表。如何修改脚本以便插入名字和姓氏而不是用户名?
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var idCol = e.range.getColumn();
var idRow = e.range.getRow();
if ( idCol == 4 && sheet.getName() =='LIST1' ) {
var Value = e.range.offset(0, -2).getValues();
if ( Value == "" ) {
var vartoday = getDate(); //Gets the current date//
sheet.getRange(idRow, 2).setValue( vartoday ); //Inserts into column 2 of the current row//
var u = Session.getEffectiveUser().getUsername(); //Gets the username of the editor//
sheet.getRange(idRow, 7).setValue(u); //Inserts into column 7 of the current row//
}
}
function getDate() {
var today = new Date();
today.setDate(today.getDate());
return Utilities.formatDate(today, 'GMT+03:00', 'dd/MM/yy');
}
}
最佳答案
看起来您在此处存储用户名 -
var u = Session.getEffectiveUser().getUsername(); //Gets the username of the editor//
然后在这里插入用户名-
sheet.getRange(idRow, 7).setValue(u); //Inserts into column 7 of the current row//
您需要在存储之前拆分名称。像这样 -
var first_name = // Split by your delimeter here and store first name
var last_name = // Split by your delimeter here and store last name
sheet.getRange(idRow, 7).setValue(first_name); //Inserts into column 7 of the current row//
sheet.getRange(idRow, 8).setValue(last_name); //Inserts into column 8 of the current row//
关于javascript - 从 Google Apps 脚本中的用户名获取姓名和姓氏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64238252/