谷歌电子表格中的单元格着色如果从单元格调用,则失败,但在从脚本调用时可以正常工作。 [英] Cell coloring in google-spreadsheet fails if it is called from a cell, but works ok when called from the script.

查看:116
本文介绍了谷歌电子表格中的单元格着色如果从单元格调用,则失败,但在从脚本调用时可以正常工作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了以下简单的函数:

pre code function test(r,c){
var sheet = 。SpreadsheetApp.getActiveSpreadsheet()getActiveSheet();
sheet.getRange(r,c).setBackground(red);
返回1;





$ p $在电子表格中,我写入= test(row(),column())



这会导致ERROR出现以下消息:
错误:您无权调用setBackground(第3行)。

如果我在脚本中创建另一个函数调用,那么这是没有问题的,如下所示:

< pre $ function test_the_test(){
test(5,4);
}

为什么我不能从电子表格单元格调用测试函数?

预先感谢您

解决方案

文档自定义函数返回值,但不能在其所在单元格外设置值。在大多数情况下,单元格A1中的自定义函数无法修改单元格A5。当然对于其他方法如setBackgroun也是如此d等。


I have created the following simple function:

function test(r,c) {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.getRange(r,c).setBackground("red");
  return 1;
}


In the spreadsheet, I write "=test(row(),column())

This results in ERROR with the following message: Error: You do not have permission to call setBackground (line 3).

It is NO problem if I create another function call in the script as follows:

function test_the_test(){
  test(5,4); 
}

Why can't I call the test function from the spreadsheet cell?

Thank you in advance

解决方案

As it is clearly explained in the documentation, Custom functions return values, but they cannot set values outside the cells they are in. In most circumstances, a custom function in cell A1 cannot modify cell A5. That is of course also true for other methods such as setBackground etc.

这篇关于谷歌电子表格中的单元格着色如果从单元格调用,则失败,但在从脚本调用时可以正常工作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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