【问题标题】:ARRAYFORMULA not working with custom formula containing IF and COUNTIFARRAYFORMULA 不适用于包含 IF 和 COUNTIF 的自定义公式
【发布时间】:2021-10-16 02:50:33
【问题描述】:

我正在使用自定义公式 (=getRedirect()) 运行 =ARRAYFORMULA()=IF(),该公式检索单元格范围内的重定向缩短 URL 的原始 URL,以获取原始 URL 中的用户 ID。如果单元格B:B 中的 URL 是重定向缩短的 URL,它会运行自定义公式,并在运行=MID() 后将用户 ID 输出到 C:C 到自定义公式的输出。如果单元格 B:B 中的 URL 是原始 URL,则在对其运行 =MID() 后,它将用户 ID 输出到 C:C=IF() 根据B:B 中的单元格值输出特定的错误消息。

这是自定义公式 -

  var response = UrlFetchApp.fetch(url, {'followRedirects': false, 'muteHttpExceptions': false});
  var redirectUrl = response.getHeaders()['Location']; // undefined if no redirect, so...
  var responseCode = response.getResponseCode();
  if (redirectUrl) {                                   // ...if redirected...
    var nextRedirectUrl = getRedirect(redirectUrl);    // ...it calls itself recursively...
    Logger.log(url + " is redirecting to " + redirectUrl + ". (" + responseCode + ")");
    return nextRedirectUrl;
  }
  else {                                               // ...until it's not
    Logger.log(url + " is canonical. (" + responseCode + ")");
    return url;
  }
}

这是我在 C:C 中输入的内容 - =ARRAYFORMULA(IF($B2:B="","<--- Please insert TikTok video's URL",IF(COUNTIF($B2:B,"*/video/*"),MID($B2:B,FIND("~",SUBSTITUTE($B2:B,"/","~",5))+1,19),IFERROR(MID(getRedirect($B2:B),FIND("~",SUBSTITUTE(getRedirect($B2:B),"/","~",6))+1,19),"<--- error in URL"))))

公式正常输出,没有=ARRAYFORMULA()。不知道是不是因为C:C的公式中=ARRAYFORMULA()=COUNTIF()之间的冲突。

具有预期结果的样本表 - https://docs.google.com/spreadsheets/d/1rJKm5KIT8itZs2AC0wdDZ-CGar4mERu4jzJ3mN7KMb8

【问题讨论】:

    标签: google-sheets google-sheets-formula array-formulas countif


    【解决方案1】:

    要使用ARRAYFORMULA 的自定义函数,您需要修改您的脚本。 看到这个example

    【讨论】:

    • 嗨@idfurw! @RonM 根据您提供的文章中的示例帮助我修改了脚本。不幸的是,它不适用于 =arrayformula()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2021-12-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多