简体   繁体   English

应用程序脚本条件格式的值不在数组中

[英]Apps script conditional formatting for value not in array

在此处输入图像描述

I have a column containing US state abbreviations.我有一列包含美国各州的缩写。 I'd like to have an array of all 50 states:我想要一个包含所有 50 个状态的数组:

const states = ['DE','AK','TX','CA' .........]

that the value of each cell in the column is compared against.与列中每个单元格的值进行比较。 If its not one of the states I'd like to format it red.如果它不是我想将其格式化为红色的状态之一。

I've looked at conditional formatting ( https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder#whenTextDoesNotContain(String) ) where they have sample code like:我查看了条件格式( https://developers.google.com/apps-script/reference/spreadsheet/conditional-format-rule-builder#whenTextDoesNotContain(String) ),其中有示例代码,例如:

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:B3");
var rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextDoesNotContain("hello")
.setBackground("#FF0000")
.setRanges([range])
.build();
var rules = sheet.getConditionalFormatRules();
rules.push(rule);
sheet.setConditionalFormatRules(rules);

Is there a conditional rule that would allow (in pseudocode):是否有条件规则允许(在伪代码中):

.whenTextDoesNotContain(states)

Here is an example of using a custom formula in conditional formatting.以下是在条件格式中使用自定义公式的示例。

I create a data set in A1:A5.我在 A1:A5 中创建了一个数据集。

Then I put conditional formatting on A7:A10.然后我在 A7:A10 上设置了条件格式。 The custom formula is =ISNA(MATCH(A7,A$1:A$5,0))自定义公式为=ISNA(MATCH(A7,A$1:A$5,0))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM