Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌工作表脚本:如何自动更新谷歌工作表';在新列中';_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 谷歌工作表脚本:如何自动更新谷歌工作表';在新列中';

Javascript 谷歌工作表脚本:如何自动更新谷歌工作表';在新列中';,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我将股票数据从谷歌金融导入谷歌资产负债表, 能够使用谷歌脚本在同一个单元格上自动更新, 但不知道如何将新数据放到下一个可用的单元格中 这是一个用于获取数据的程序,它只更新单元格A1上的数据,我不知道如何让它将价格更新为B1、C1、D1,以便将来进行更新 function GetPrice() { SpreadsheetApp.getActiveSpreadsheet().getRange('A1').setValue('=GOOGLEFINANCE("GOOG", "price")');

我将股票数据从谷歌金融导入谷歌资产负债表, 能够使用谷歌脚本在同一个单元格上自动更新, 但不知道如何将新数据放到下一个可用的单元格中

这是一个用于获取数据的程序,它只更新单元格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")');
}

为了理解工作表API,您可以查看。

如果要将值设置为下一列,即如果第一个值在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")');
}

要了解工作表API,您可以查看。

分享您的代码是个好主意,因为我只需要编写获取数据函数(更新)的代码,但不知道让他们在新单元格上输入数据的代码。请告知MSHOAIB91分享您的代码是一个好主意,我只需要为获取数据功能(更新)编写代码,但不知道如何让他们在新单元格上输入数据。请建议MSHOAIB91太好了!你可以点击最有用答案下面的绿色勾号来结束你的问题。太好了!您可以单击“最有用的答案”下的绿色勾号关闭您的问题。