简体   繁体   English

具有多个 IF 条件的 Google Apps 脚本

[英]Google Apps Script with multiple IF conditions

I use this formula in Column G我在 G 列中使用了这个公式

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

Applying this formula for 30k data make my sheet slow.将此公式应用于 30k 数据会使我的工作表变慢。 Need to convert to script.需要转换成脚本。

As If and IFS is used in same formula, I am facing difficult to convert this to Script.由于 If 和 IFS 在相同的公式中使用,我很难将其转换为脚本。

Condition:健康)状况:

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

Given that you need the columns A,C,E I used the range A2:E and paste the resulting data in column F :鉴于您需要列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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM