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

查看:34
本文介绍了如何在 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))

我收到错误无法将数组转换为(类)[]."

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天全站免登陆