在自定义脚本功能(Google表格+ GAS)中使用ARRAYFORMULA [英] Use ARRAYFORMULA in a custom script function (Google Sheets + GAS)

查看:98
本文介绍了在自定义脚本功能(Google表格+ GAS)中使用ARRAYFORMULA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以调整此功能以与电子表格中的ARRAYFORMULA一起使用?

Is there any way to adjust this function for use with ARRAYFORMULA in spreadsheets?

function SendTelegram(botSecret, chatId, body) {
  var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
}

而不是像这样对每行使用一个公式:

Instead of using a formula for each line like this:

=SendTelegram($H$1,$I$1,F2)
=SendTelegram($H$1,$I$1,F3)
=SendTelegram($H$1,$I$1,F4)
=SendTelegram($H$1,$I$1,F5)

通过这种方式:

=ARRAYFORMULA(SendTelegram($H$1,$I$1,F2:F))

返回以下消息:

Limit Exceeded: URLFetch URL Length. (line 22).

推荐答案

类似的事情,您可能必须适应所需的特定行为.

Something like this, you might have to adjust to the particular behavior you want.

function SendTelegram(botSecret, chatId, body) {
  if (body.map) { // is array?
  var response = body.map(function(b) {return SendTelegram(botSecret,chatId,b);});
   } else {
  var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
  }
}

这篇关于在自定义脚本功能(Google表格+ GAS)中使用ARRAYFORMULA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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