如何在ARRAYFORMULA中为一系列单元格使用自定义函数? [英] How to use a custom function in an ARRAYFORMULA for a range of cells?

查看:592
本文介绍了如何在ARRAYFORMULA中为一系列单元格使用自定义函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Google Form that is populating a Google Sheet. Due to having custom formulas in the sheet to manipulate the data populated from the form I am using ARRAYFORMULA to apply to all rows in a column.

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

I have a custom function to encode rows containing 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))

When I call this function inside of ARRAYFORMULA(base64EncodeWebSafe(T2:T))

我收到错误消息无法将数组转换为[class] []。

I receive an error "Cannot convert Array to (class)[]."

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

What I expect to happen is to apply the encoding function to the range T2:T

推荐答案

自定义功能指南中。我已经适应了指南中使用的实现,但是您可以做其他事情。基本上,如果使用ARRAYFORMULA,则需要将输入视为二维数组。

This is described in the Custom Functions guide. I've adapted the implementation used in the guide, but you could do something else. Basically, if using ARRAYFORMULA, then you need to treat the input as a 2-dimensional array.

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);
    }
  }
}

这篇关于如何在ARRAYFORMULA中为一系列单元格使用自定义函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆