If statement 大家好,请帮我检查一下谷歌应用程序脚本中的IF语句

If statement 大家好,请帮我检查一下谷歌应用程序脚本中的IF语句,if-statement,google-apps-script,google-sheets,google-sheets-api,spreadsheet,If Statement,Google Apps Script,Google Sheets,Google Sheets Api,Spreadsheet,我想制作一个代码,为我的工作表分配逻辑输入。我用IF来做。我的代码运行成功,但逻辑不起作用。我已经检查过很多次了,但没有发现什么地方不对劲。你能帮我吗?我卡住了。请查看我的示例表和脚本以了解更多信息。谢谢大家! 如果每次运行只需要一个操作解析,则需要使用else If链接语句: if(statement){ Action }else if (statement2){ Action2 }else if... 您可以通过这种方式简化代码。 (注意,我使用const变量声明而不是va

我想制作一个代码,为我的工作表分配逻辑输入。我用IF来做。我的代码运行成功,但逻辑不起作用。我已经检查过很多次了,但没有发现什么地方不对劲。你能帮我吗?我卡住了。请查看我的示例表和脚本以了解更多信息。谢谢大家!


如果每次运行只需要一个操作解析,则需要使用else If链接语句:

if(statement){
    Action
}else if (statement2){
    Action2
}else if...

您可以通过这种方式简化代码。 (注意,我使用const变量声明而不是var())

这样,您只需测试一次常见条件。
使用函数可以根据输入值“ActiveCellValue”清楚地显示脚本的行为。

但是逻辑不起作用
所需的逻辑是什么?你想完成什么?谢谢你Halijean,你的代码对我有用
if(statement){
    Action
}else if (statement2){
    Action2
}else if...
function logic() {
    const ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    const activeCell = ss.getActiveCell();
    const activeCellValue = activeCell.getValue();

    if (activeCell.getColumn() === 1 && activeCell.getRow() > 1 && ss.getSheetName() == "mama") {
        switch(activeCellValue) {
            case 'Yes':
                activeCell.offset(0, 1).clearContent();
                activeCell.offset(0, 1).setValue('1');
                break;
            case 'Half':
                activeCell.offset(0, 1).clearContent();
                activeCell.offset(0, 1).setValue('1/2');
                break;
            case 'No':
                activeCell.offset(0, 1).clearContent();
                activeCell.offset(0, 1).setValue('0');
                break;
        }
    }
}