简体   繁体   English

Google Sheet Script:如何在新专栏中自动更新Google Sheet'

[英]Google Sheet Script : How to autoupdate Google Sheet 'in new column'

I imported stock data from GoogleFinance to GoogleSheet , and able use Google script for making it auto update on the same cell, but do not know how to make it put new data on the next available cell. 我将库存数据从GoogleFinance导入到GoogleSheet ,并且可以使用Google脚本在同一个单元格上自动更新,但不知道如何将新数据放在下一个可用单元格上。

This is the one for getting data, which only update the data on Cell A1, I don't know how to make it update the price to B1, C1, D1 for its future update. 这是获取数据的一个,它只更新Cell A1上的数据,我不知道如何将它的价格更新为B1,C1,D1以供将来更新。

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

Thanks in advance guys. 先谢谢你们。

If you want to set the value to the next column ie if first value was in A1, now on next function call you want values to be in B1, C1 and continue, you need to update your code to get the last column index and then setting the value to the next column. 如果要将值设置为下一列,即如果第一个值在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")');
}

For understanding of sheet API, you can check out the documentation . 要了解表API,您可以查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM