多列条件格式 [英] Multiple column conditional formatting

查看:102
本文介绍了多列条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图根据内容设置单个单元格的背景颜色。

我试图根据内容设置单个单元格的背景颜色该细胞和另一个细胞。



例如,如果特定单元格为空,并且B1没有x,我希望A1的背景颜色为绿色。如果任何一种情况都没有得到满足,也就是在A1或B1中没有x,我不希望A1突出显示。



然后我希望将其应用于整个列A,并在每次编辑列A或B时更新它。

解决方案

 values = s.getRange(' A1:B')。getValues(),
row,len,colors = [];

//检查条件值
for(row = 0,len = values.length; row< len; row ++){
if(values [row] [0 ] ==''&&& amp; values [row] [1]!='x')
colors.push(['green']);
else colors.push(['white']);}

//在新元素中设置新颜色
s.getRange('A1')。offset(0, 0,len).setBackgrounds(colors);
}


I have searched for an answer to this, but I cannot find one anywhere.

I am trying to set a background color of an individual cell based on the contents of that cell and another cell.

For example, I want A1 to have a background color of green if that specific cell is blank AND if B1 does not have an "x" in it. If either condition is not met, i.e. there is something in A1 or B1 does not have an "x", I don't want A1 to be highlighted.

I then want to apply this to the entire column A, and have it update each time columns A or B are edited.

解决方案

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(),
      s = ss.getSheetByName('Sheet1'),
      values = s.getRange('A1:B').getValues(),
      row, len, colors = [];

  // CHECK VALUES FOR CONDITIONS
  for (row = 0, len = values.length; row < len; row++) {
    if (values[row][0] == '' && values[row][1] != 'x')
      colors.push(['green']);
    else colors.push(['white']);}

  // SET NEW COLORS ALL AT ONCE
  s.getRange('A1').offset(0, 0, len).setBackgrounds(colors);
}

这篇关于多列条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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