![](/img/trans.png)
[英]Make a custom function in Google sheets script to work with "ArrayFormula"
[英]Use ARRAYFORMULA in a custom script function (Google Sheets + GAS)
有什么方法可以调整此函数以与电子表格中的ARRAYFORMULA
一起使用吗?
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");
}
而不是像这样为每一行使用公式:
=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).
像这样的事情,你可能必须适应你想要的特定行为。
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");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.