如果从单元格调用,则 google-spreadsheet 中的单元格着色会失败,但从脚本调用时可以正常工作. [英] Cell coloring in google-spreadsheet fails if it is called from a cell, but works ok when called from the script.
问题描述
function test(r,c) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange(r,c).setBackground("red");
return 1;
}
<小时>
在电子表格中,我写=test(row(),column())
In the spreadsheet, I write "=test(row(),column())
这会导致错误并显示以下消息:错误:您无权调用 setBackground(第 3 行).
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?
提前致谢
推荐答案
正如 文档,自定义函数返回值,但它们不能在它们所在的单元格之外设置值.在大多数情况下,单元格A1中的自定义函数不能修改单元格A5.这是当然的也适用于其他方法,例如 setBackground 等.
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.
这篇关于如果从单元格调用,则 google-spreadsheet 中的单元格着色会失败,但从脚本调用时可以正常工作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!