简体   繁体   English

自动更改用户编辑的单元格背景-Google表格

[英]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.

相关问题 经过背景验证的Google表格api用于编辑和读取单元格的格式 - Background authenticated google sheets api to edit and read format of a cell 更改谷歌表格中单元格的颜色 - Changing Color of cell in google sheets 自动将Google表格中单元格内容大写的脚本? - Script to automatically capitalize contents of a cell in Google Sheets? 从单元格自动重命名 Google Sheets 文件 - Renaming Google Sheets File Automatically From A Cell 在谷歌表格中的单元格中输入条目后,立即锁定整个单独的行,以便其他共享用户进行编辑 - Lock the Entire individual Row immediately for other shared user to edit after a entry made in a cell in google sheets 编辑谷歌表格应用脚本中过滤行中的单元格值 - Edit cell value from filtered row in app script for google sheets 在Google表格中输入数据后,自动保护单元格/范围 - Automatically protect a cell / range after inputting data in Google Sheets 从 JavaScript 下拉菜单更改 Google 表格单元格值 - Changing Google Sheets Cell Value from JavaScript Dropdown Menu 为 Google 表格中的单元格设置背景颜色 API JavaScript - Set Background Color to a Cell in Google Sheets API JavaScript 谷歌表格中的按钮,当点击时,改变特定单元格的背景 - Button in google sheets, when clicked, changes the background of a specific cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM