javascript - 从 Google Apps 脚本中的用户名获取姓名和姓氏
问题描述
我使用脚本自动插入日期和用户名来填写字符串。几个人填表。如何修改脚本以便插入名字和姓氏而不是用户名?
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//
推荐阅读
- java - NullPointerException 当 RecyclerView 项目被点击时 null 对象引用
- javascript - 如何确定网站是否嵌入了 iframe?
- reactjs - Redux-sagas 无法识别 backend.js 文件中的函数
- python - 需要修复json格式
- python - Python ctypes 加载 dll 库没有错误,但在函数调用时不返回预期结果
- javascript - net::ERR_ABORTED 403 (Forbidden) 使用商店定位器时代码点火器中的错误
- java - 如何在 PojoObject 的 Firestore 中将 LocalDateTime 存储为字段?
- android - Android房间数据库没有立即在数据库中插入数据
- rust - 包含一段数据和被引用数据的结构中的生命周期
- arrays - Delphi 数组在 2D 和 1D 之间来回转换