0

我创建了一个将数据提交到 Google 电子表格的 Google 表单。我正在尝试根据特定列中的值对行进行颜色编码 - 没问题。但是,我正在使用 onEdit 函数,当用户提交表单时,行不会改变颜色。只有当我编辑特定单元格时,行才会改变颜色,因此 onEdit 函数。确实,Google 似乎没有将表单提交视为电子表格中的“编辑”,即使从技术上讲,它是一种编辑。我试图复制并粘贴该函数并将其重命名为 onOpen,但这也不起作用。我在这里想念什么?我已经在下面发布了代码,我非常感谢您能负担得起的任何帮助。另外,我是脚本新手,所以请放轻松;)

// Color code rows based on the status of the ticket
function onEdit(e) {
 if (e) { 
    var ss = e.source.getActiveSheet();
    var r = e.source.getActiveRange(); 

    // If you want to be specific
    // do not work in first row
    // do not work in other sheets except "Sheet1"
    if (r.getRow() != 1 && ss.getName() == "Sheet1") {

        // E.g. status column is 6th (F)
        status = ss.getRange(r.getRow(), 6).getValue();

        // Specify the range with which You want to highlight
        // with some reading of API you can easily modify the range selection properties
        // (e.g. to automatically select all columns)
        rowRange = ss.getRange(r.getRow(),1,1,6);

        // This changes row color
        if (status == 'New') {
            rowRange.setBackgroundColor("#f26c4f");
        } else if (status == 'In Progress') {
            rowRange.setBackgroundColor("#fff568");
        } else if (status == 'Ordered') {
            rowRange.setBackgroundColor("#68baff");
        } else if (status == 'Completed') {
            rowRange.setBackgroundColor("#a2e7a5");  
        // DEFAULT
        } else if (status == '') { 
            rowRange.setBackgroundColor("#FFFFFF");
        }   
    }
 }
} 
4

1 回答 1

0

“谷歌似乎没有将表单提交视为电子表格中的“编辑”,即使从技术上讲,它是一个编辑”

这就是为什么有一个On form submit功能,请参阅此处的文档,可从脚本编辑器资源 > 当前脚本触发器中获得 在此处输入图像描述

于 2013-04-02T15:25:19.747 回答