我可以将数组从Google

我可以将数组从Google

本文介绍了我可以将数组从Google Spreadsheet传递到Google App Script方法中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从Google Spreadsheet将数组传递到Google App Script方法中吗?

Can I pass an array into a Google App Script method from a Google Spreadsheet?

假设我有一个App Script函数,该函数期望一个包含两个元素的列表(请注意:此示例仅是一个示例,因此请不要告诉我,如果我只是将每个元素作为单独的参数传递,那么我的问题将得到解决).如何在Google Spreadsheet单元格中调用此函数?

Suppose I have an App Script function that expects a list with two elements (note: this example is just an example so please do not tell me that my problem would be solved if I simply passed each element as a separate argument). How do I call this function from a Google Spreadsheet cell?

我都尝试过:'= myFunc([1,2])'和'= myFunc((1,2))'都给我一个解析错误.

I've tried both: '=myFunc([1,2])' and '=myFunc((1,2))' and both give me a Parse Error.

推荐答案

在电子表格公式中,您可以使用花括号构造一个嵌入式数组.分号是行定界符;逗号(或使用逗号作为小数点分隔符的语言环境中的反斜杠)是列定界符.

In a spreadsheet formula, you can construct an embedded array using curly braces. Semi-colons are row delimiters; commas (or backslashes in locales that use a comma for the decimal separator) are column delimiters.

现在,当将此类嵌入式数组传递给Google Apps脚本时,它们将转换为二维Javascript数组,就像引用的范围一样.

Now when such embedded arrays are passed to Google Apps Script, they are converted to a 2-dimensional Javascript array, just like referenced ranges are.

所以:

= myFunc({1,2})

= myFunc({1; 2})

function myFunc(value)
{
}

在第一个公式中, value 将为 [[[1,2]] .第二个是 [[1],[2]] .

In the first formula, value will be [[1, 2]]. In the second, it will be [[1], [2]].

这篇关于我可以将数组从Google Spreadsheet传递到Google App Script方法中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 05:21