[英]Changing cell background on user edit automatically - Google Sheets
I'm trying to make a script that automatically change the background color of cells depending on which user edits it. 我正在尝试制作一个脚本,该脚本根据哪个用户对其进行编辑来自动更改单元格的背景颜色。 I currently have this code but it doesn't do anything.
我目前有这段代码,但是它什么也没做。 We need to know which user edits or creates a new entry.
我们需要知道哪些用户正在编辑或创建新条目。
I just need the cells in the first column to change background color. 我只需要第一列中的单元格即可更改背景色。 This is for a Data base I'm working with 4 other people
这是我正在与另外4个人一起使用的数据库
function checkEdits() {
var s = SpreadsheetApp.getActiveSheet();
//checks that we're on the correct sheet
if (s.getName() == "Sheet1") {
var r = s.getActiveCell();
//checks the column
if (r.getColumn() == 1) {
var email = r.Session.getActiveUser().getEmail();
if (email == "XXXXX@gmail.com") {
r.setBackground('#dbbf94');
}
if (mail == "YYYYYY@gmail.com") {
r.setBackground('#94dbab');
}
if (mail == "ZZZZZZ@gmail.com") {
r.setBackground('#a2bfdf');
}
if (mail == "MMMMMMMM@gmail.com") {
r.setBackground('#cf9ce5');
}
if (mail == "NNNNNNN@gmail.com") {
r.setBackground('#dfa2b1');
}
}
}
}
I expect that when a user edit a cell un Column A, the same cell changes its background to the specific user color 我希望当用户在A列中编辑单元格时,同一单元格将其背景更改为特定的用户颜色
You may want to try this. 您可能想尝试一下。 If parts aren't clear, let me know, I'll give you more details.
如果部分内容不清楚,请告诉我,我会为您提供更多详细信息。
function onEdit(e){ if (e.range.getSheet().getSheetId() == e.source.getSheetByName("Sheet1").getSheetId() && e.range.getColumn() == 1.0){ switch (e.user){ case "XXXXX@gmail.com": e.range.setBackground('#dbbf94'); break; case "YYYYYY@gmail.com": e.range.setBackground('#94dbab'); break; case "ZZZZZZ@gmail.com": e.range.setBackground('#a2bfdf'); break; case "MMMMMMMM@gmail.com": e.range.setBackground('#cf9ce5'); break; case "NNNNNNN@gmail.com": e.range.setBackground('#dfa2b1'); break; default: e.range.setBackground('white'); } } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.