从自定义函数设置注释

Set note from custom function

本文关键字:注释 设置 自定义函数      更新时间:2023-09-26


我正在努力解决以下问题:
我有一个电子表格负责跟踪我的股票市场投资。它调用外部服务以获得当前价格的CSV

因此,有一个函数customFunction()调用UrlFetchApp并返回商品的当前价格。我希望它在调用它的单元格中添加一个注释,其中包含当前日期时间。类似这样的东西:

function customFunction() {
  //get price from csv
  var url = "http://sth.com";
  var csv = UrlFetchApp.fetch(url);
  var result = Utilities.parseCsv(csv);
  var currentValue = parseFloat(result[1][6]);
  //set note
  SpreadsheetApp.getActiveSheet().getActiveCell().setNote("Hey, I'm the note with the datetime");
  //return value so it can be set as cell value
  return currentValue;
}

我从单元格E21(值=customFunction()(调用此函数。因此,一切都按计划进行,除了本应设置注释的行。我确信我得到了正确的单元格(通过返回A1符号作为值进行测试(。我得到错误:

error: You do not have permission to call setNote

有人知道是否可以为从该函数调用自定义函数的单元格设置注释吗?或者,您可能有任何解决方法的想法,比如捕捉函数重新加载新数据的瞬间并将其用作触发器?

您的问题是由于权限限制:https://developers.google.com/apps-script/execution_custom_functions#permissions
函数SpreadsheetApp.getActiveSheet((.getActiveCell((不是匿名的,不能在这里使用。不幸的是,我不知道任何有效的解决方法