[英]How to use a custom function in an ARRAYFORMULA for a range of cells?
我有一個填充 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
這在自定義函數指南中進行了描述。 我已經調整了指南中使用的實現,但您可以做其他事情。 基本上,如果使用 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);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.