谷歌电子表格条件格式脚本 [英] Google Spreadsheet conditional formatting script
问题描述
我想弄清楚如何在 google 电子表格上使用条件格式,类似于您可以通过公式在 excel 中执行的操作.
I am trying to figure out how to use conditional formatting on a google spreadsheet similar to what you can do in excel via a formula.
如果单元格 O2 的值为X",我希望单元格 A2 更改为绿色,并且这将在两列一直向下完成.我知道这需要一个脚本.
I want cell A2 to change to Green if cell O2 has a value of "X" and this will be done on both columns all the way down. I know this will require a script.
我遇到了一个类似的链接,但我不知道如何调整它以满足我的需要.这是可以做到的吗?
I ran across a link that is similar but i do not know how to adjust it to meet my needs. Is this something that can be done?
链接:https://webapps.stackexchange.com/questions/16745/google-spreadsheets-条件格式
推荐答案
这是您可以用来执行您所描述的操作的脚本:
Here's a script you could use to do what you described:
function formatting() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var columnO = sheet.getRange(2, 15, sheet.getLastRow()-1, 1);
var oValues = columnO.getValues();
for (var i = 0; i < oValues.length; i++) {
if (oValues[i][0] == 'X') {
sheet.getRange(i + 2, 1, 1, 1).setBackgroundColor('green');
}
}
}
这篇关于谷歌电子表格条件格式脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!