[英]Google Sheet Custom Function not getting populated from AppScript
I am trying to create a portfolio tracker in google sheets.我正在尝试在谷歌表格中创建投资组合跟踪器。 For that I have written a custom function in App Script.
为此,我在 App Script 中编写了自定义 function。 The function is taking two inputs - ticker symbol (tickers) and amount (values).
function 采用两个输入 - 股票代码(股票代码)和金额(值)。 Whenever I try to call the function in excel sheet, it is throwing an error as 'Reference does not exist'
每当我尝试在 excel 表中调用 function 时,它都会抛出错误,因为“参考不存在”
function MyPortfolio(tickers, values)
{
var total = []
var sums = {}
for (i=0;i<tickers.length; i++)
{
var t = tickers[i].toString()
if(t!="Cash")
{
if(t in sums)
{
sums[t]+=Number(values[i])
}
else
{
sums[t]=Number(values[i])
}
}
}
for(var ticker in sums)
{
if(sums[ticker]>0)
{
total.push[ticker, sums[ticker]]
}
}
return total
}
Need help需要帮忙
An empty array is not a valid return value.空数组不是有效的返回值。
Make sure that total is not empty.确保总计不为空。
If you do not want to return a value, you can return an array with empty values ["",""] .如果你不想返回一个值,你可以返回一个空值的数组["",""] 。
The issue is resolved.问题已解决。 It was a syntax error
这是一个语法错误
.
.
total.push([ticker, sums[ticker]])
.
.
I forgot to put round brackets (...)
我忘了放圆括号
(...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.