【问题标题】:How to use a custom function in an ARRAYFORMULA for a range of cells?如何在 ARRAYFORMULA 中为一系列单元格使用自定义函数?
【发布时间】:2019-05-05 05:28:33
【问题描述】:

我有一个正在填充 Google 表格的 Google 表单。由于工作表中有自定义公式来操作从表单填充的数据,因此我使用 ARRAYFORMULA 应用于列中的所有行。

我有一个自定义函数来编码包含 html 的行

function base64EncodeWebSafe(input) {

  try {
    // Try and fetch the specified url.
    return Utilities.base64EncodeWebSafe(input);

  } catch (e) { 
    Utilities.sleep(1000);
    return Utilities.base64EncodeWebSafe(input);

  }
}

当我在 ARRAYFORMULA(base64EncodeWebSafe(T2:T)) 中调用此函数时

我收到一个错误“无法将数组转换为(类)[]。”

我期望发生的是将编码函数应用于范围 T2:T

【问题讨论】:

    标签: google-apps-script google-sheets array-formulas custom-function


    【解决方案1】:

    这在Custom Functions guide 中有描述。我已经调整了指南中使用的实现,但您可以做其他事情。基本上,如果使用 ARRAYFORMULA,则需要将输入视为二维数组。

    function base64EncodeWebSafe(input) {
      if (input.map) { // Test whether input is an array.
        return input.map(base64EncodeWebSafe)
      } else {
        try {
          return Utilities.base64EncodeWebSafe(input);
        } catch (e) {
          Utilities.sleep(1000);
          return Utilities.base64EncodeWebSafe(input);
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2022-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多