gpt4 book ai didi

javascript - 谷歌表格脚本: How to autoupdate Google Sheet 'in new column'

转载 作者:行者123 更新时间:2023-11-28 05:50:14 24 4
gpt4 key购买 nike

我将股票数据从 GoogleFinance 导入到 GoogleSheet,并能够使用 Google 脚本使其在同一单元上自动更新,但不知道如何让它将新数据放在下一个可用单元格上。

这是获取数据的,只更新Cell A1上的数据,我不知道如何让它更新价格到B1,C1,D1以供将来更新。

function GetPrice() {
SpreadsheetApp.getActiveSpreadsheet().getRange('A1').setValue('=GOOGLEFINANCE("GOOG", "price")');
}

提前谢谢大家。

最佳答案

如果您想将值设置为下一列,即如果第一个值位于 A1 中,那么现在在下一个函数调用中您希望值位于 B1、C1 中并继续,您需要更新代码以获取最后一列索引,然后将值设置为下一列。

function GetPrice(){
var sheet = SpreadsheetApp.getActiveSheet();
var lastCol = sheet.getLastColumn();
// increment the column index
lastCol ++;
// Setting first parameter i.e row index to 1 for the value to appear in the first row
sheet.getRange(1, lastCol).setValue('=GOOGLEFINANCE("GOOG", "price")');
}

要了解sheet API,您可以查看documentation .

关于javascript - 谷歌表格脚本: How to autoupdate Google Sheet 'in new column' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38138947/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com