自定义函数抛出“您没有设置值所需的权限";错误 [英] Custom function throws a "You do not have the permission required to setValue" error

本文介绍了自定义函数抛出“您没有设置值所需的权限";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Google 电子表格中的单元格设置一些值:

I am trying to set some value to a cell in a Google Spreadsheet:

    function exampleFunction() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sheet = ss.getSheets()[0];
      var range1 = sheet.getRange("A1");
      var value1 = range1.getValue();
      value1+=1;
      range1.setValue(2);
      return value1;
    }

如果我试图用这个函数影响一个单元格,就会出现这个错误:

If I am trying to affect a cell with this function, this error appears:

您没有设置值所需的权限.(第 10 行,文件ddd")

You do not have the permission required to setValue. (line 10, file "ddd")

你知道我是怎么做到的吗?我实际上希望受影响的单元格取单元格 A1 的值并将 A1 的值增加 1.

Do you know how I could make that possible? I actually want the affected cell to take the value of the cell A1 and increase the value of A1 by 1.

推荐答案

来自文档:

自定义函数返回值,但它们不能在它们所在的单元格之外设置值.在大多数情况下,单元格 A1 中的自定义函数不能修改单元格 A5.但是,如果自定义函数返回双精度数组,则结果会溢出包含该函数的单元格并填充包含自定义函数的单元格下方和右侧的单元格.您可以使用包含 return [[1,2],[3,4]]; 的自定义函数对此进行测试.

参考:电子表格中的自定义函数

这篇关于自定义函数抛出“您没有设置值所需的权限";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆