setBackground()或setFontColor在GAS中不起作用 [英] setBackground() or setFontColor not working in GAS

查看:75
本文介绍了setBackground()或setFontColor在GAS中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让我的脚本突出显示一个范围,并且在调试了一下之后,发现类型调用似乎有问题。

I was having trouble getting my script to highlight a range and after debugging for a bit, realized that there seems to be something wrong with the call of type

range.setBackground("name of color");

所以,我去了GAS参考网站并使用他们页面中的示例: https://developers.google.com/apps-script/reference/spreadsheet/范围#setFontColor(String)

So, I went to GAS reference website and used the example from their page: https://developers.google.com/apps-script/reference/spreadsheet/range#setFontColor(String)

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("B2");
cell.setFontColor("red");

此代码导致!ERROR。
如果我在setFontColor()调用之前强制返回,一切正常。 (我的意思是它从函数返回而没有错误,但当然,没有设置颜色)。

This code results in !ERROR. If I force a return before setFontColor() call, all is fine. (and by fine I mean it returns from the function without an error, but of course, without having set the color).

我在做什么错了?

推荐答案

你还没有提供足够的信息,但我认为你是从一个单元格公式调用你的函数作为一个自定义函数。看到文档,就像你不能改变当前单元格以外的单元格一样。

You havent put enough info, but i assume you are calling your function from a cell formula as a custom function. See the docs, used like that you cant change a cell other than the current cell.

这篇关于setBackground()或setFontColor在GAS中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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