【问题标题】:Google Apps Script with multiple IF conditions具有多个 IF 条件的 Google Apps 脚本
【发布时间】:2023-03-12 01:45:01
【问题描述】:

我在 G 列中使用了这个公式

=IF(ISBLANK(A3),"User missing",IFS(C3=E3,0,E3="","Empty Data",C3<>E3,"Wrong Data"))

将此公式应用于 30k 数据会使我的工作表变慢。需要转成脚本。

由于 If 和 IFS 在同一个公式中使用,我很难将其转换为脚本。

条件:

If Column A is Empty then "User Missing"
If A have data, 
then condition is
If E is empty then "Empty Data"
If C and E is not equal then "Wrong Data"
If C and E is equal then 0

【问题讨论】:

    标签: javascript google-apps-script google-sheets


    【解决方案1】:

    鉴于您需要A,C,E 列,我使用了A2:E 范围并将结果数据粘贴到F 列中:

    function myFunction(){
        const ss = SpreadsheetApp.getActiveSpreadsheet();
        const sh = ss.getSheetByName("Sheet1");
        const vals = sh.getRange("A2:E"+sh.getLastRow()).getValues();
        const cvals = []; 
        vals.forEach(r=>{           
             cvals.push( [
                     r[0]==''?"User Missing":
                     r[4]==''?"Empty Data":
                     r[2]!=r[4]?"Wrong Data":0
             ])            
          });
        sh.getRange(2,6,cvals.length,1).setValues(cvals); // paste in column F
    }
    

    【讨论】:

    • 这里有同样的问题,而是 C,D,E 。如果我使用 A,C,E vals 会怎样?
    • edit根据新列更新条件。
    • @Moses 不确定您编辑了什么。您只想更改输入列?条件再次基于 C、D、E 列?请编辑此部分并更改您要使用的列字母:If Column D is Empty then "User Missing" If D have data, then condition is If E is empty then "Empty Data" If C and E is not equal then "Wrong Data" If C and E is equal then 0
    • @Moses 我更新了答案。让我知道它是否有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多