我多年来一直使用以下自定义Google Apps脚本,并且由于某种原因,它已部分停止工作。该脚本应该检索项目数组,然后在电子表格列中显示它们。这是脚本:
function myAccounts() {
var output = [], arr = JSON.parse(createArr());
for(var i=0, iLen=arr.length; i<iLen; i++) {
output.push([arr[i][0]]);
}
output = output.sort();
return output;
}
通过使用调试器,我能够看到数组似乎是正确创建的。这是函数的output
:
var arr = [
[["5383 - CATEGORY A"],["ASSESSMENT REVIEW BRD","ANNUAL FEE", "ATG ASSESS REVIEW BOARD TORONTO ", "ATG-ASSESSMENT REVIEW BRD TORONTO ",
"MPAC-PICKERING","CITIZENSHIP & IMM ON-LINEOTTAWA","JONES"]],
[["5230 - CATEGORY B"], ["RED CROSS","G(IRLS)20 SUMMIT","MOVEMBER *CHARITY","HOSP FOR SICK CHILDREN","URBAN SQUASH TORONTO"]],
[["5351 - CATEGORY C"], ["ELTE","PAYPAL *SMITH","PRAXIS INTERNATIONAL ART"]],
[["5350 - CATEGORY D"], ["PAYPAL *CANADAWIDEP","LA PARETE GALLERY","ACTIVE SURPLUS","PAYPAL *DHL EXPRESS","PRINT THREE #95","STAPLES.CA",
"FRAMING FACTORY"]],
[["5387 - CATEGORY E"], ["SWEETSERVICES","EVENT RENTAL","GLOBAL FINANCIAL","IVISA SERVICES NORTH SYDNEY","QUEST HENDERSON",
"SLS HOTEL BEVERLY HILLS","LITTLE TIKES","FAIRY FLOWER","FARICY PTY LTD","VISTAPRINT.AU","MYBAGSCOMPA","ITS MY PARTY","PAYPAL *CAMILLEPRIN"]]
]
出于某种原因,在调用该函数的电子表格的单元格中看不到此output
。它不会抛出错误,只是让单元格完全空白。
知道可能出现什么问题吗?感谢。
答案 0 :(得分:1)
输出必须是值,数组或数组数组 你有一个阵列数组,Sheets不知道如何处理 尝试通过输出
来删除一个级别[["CATEGORY A"], ["CATEGORY B"], ["CATEGORY C"]]
这将返回一行有三列
您可以通过编写output.push(arr[i][0]);
来完成我在代码中看到的内容
我假设arr[i][0]
已经是一个元素数组。这就是为什么会发生这种情况。