可以直接把Google finance 写到一个数组中吗?

Can you write Google finance directly to an array?

googlefinance 可以将结果直接写入数组吗?我目前正在先将其写入 sheet,然后将 sheet 范围拉入数组。如果我可以将它直接写入一个数组,它会节省很多处理,所以我正在调查。如果您有这方面的知识和专长,可以告诉我吗?

尝试时出现错误。是语法不正确还是我试图做的不可能?我想避免写入 sheet 以节省时间和 sheet 处理。但不确定是否允许函数写入变量而不是 sheet

function TEST() {

 var APPLEPRICEARRAY = GOOGLEFINANCE("AAPL","price","1/1/2009","12/31/2020","WEEKLY")

};

只是语法错误吗?

您似乎混淆了 Google Sheets 应用程序中公开的函数(公式)与 Google 中可用的 services Apps 脚本环境。您编写的内容需要 GOOGLEFINANCE 成为“附加”到全局范围的服务,因此 是的,这是不正确的

但是你得到的错误不是 syntax 错误,你的 reference 是无效的(没有 GOOGLEFINANCE 变量是永远在全局范围内声明,因此可以引用none),因此你得到ReferenceError.

googlefinance 可以将结果直接写入数组吗?

不,由于上述原因,它不能。对此我深表歉意,但您是在比较苹果和橙子:数组是 data structure (an indexed collection,准确地说)在 JavaScript(Google Apps 脚本语言基于)中,而公式甚至不是内置对象:它们不是语言的一部分。

难道我想做的不可能吗?

很遗憾,Google财务APIhas been shut down好久了,所以不行,不可能。


不用全大写尖叫也被认为是一种常见的礼貌

代码示例显示您正在尝试将 Google 表格函数用作 Google Apps 脚本/JavaScript 函数。那是不可能的。

很遗憾,Google 金融没有 Google Apps 脚本高级服务,也没有 API。

来自https://groups.google.com/g/google-finance-apis

Dear Finance API users,

As you may have heard from the Google Developers Blog, Google is doing an API spring cleaning. One of the APIs affected is the Google Finance API (both the Portfolio API and the Finance Gadgets and Tools API), which will be shut down on October 20, 2012.

参考资料