使用“for each row”和嵌套“for”循环的条件格式(颜色)问题你好,
我在脚本的末尾,我在不同的列(数字和字符)中汇总了一堆数据。
循环格式化满足特定条件的数字单元格很容易,但我在为包含特定子字符串的字符列分配颜色时遇到了一些问题。
例如,一个单元格(具有以下内容:1,1,2,1,1,2,3,3)应该是红色的,因为它包含 1 次出现的字符“3”。
如果我指定单元格的全部内容,没问题,但我尝试相应地查找“3”和颜色 -> 失败。
我已经添加了下面的脚本。
任何建议,将不胜感激。
最好的,
塞巴斯蒂安
Names Default To Here( 1 );
clear log();
dt = New Table( "test",
Add Rows( 8 ),
New Column( "unique_group_id",
Character,
"Nominal",
Set Values(
{"ELN-19-0588-A", "ELN-19-0588-B", "ELN-19-0588-C", "ELN-19-0588-D",
"ELN-19-0588-E", "ELN-19-0588-F", "ELN-19-0588-G", "ELN-19-0588-H"}
),
Set Display Width( 115 )
),
New Column( "FOB max",
Character,
"Nominal",
Set Selected,
Set Values(
{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
"0,0,3,0,0,1,0,2", "1,1,2,1,1,2,3,3", "0,0,0,0,0,0,0,0",
"4,2,2,3,2,3,3,4", "1,0,0,1,1,1,1,1"}
)
),
New Column( "glib1 % PBS - potatoe",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Set Selected,
Set Values( [100, 113.39, 108.3, 156.38, 822.21, 768.51, 487.2, 222.56] )
),
New Column( "calb (IHC) cere",
Character,
"Nominal",
Set Values(
{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
"0,0,0,0,0,0,0,0", "3,4,3,4,3,3,3,4", "3,3,3,5,2,3,3,3",
"0,0,0,0,0,0,0,0", "0,0,0,0,0,0,1,0"}
)
)
);
wait(2);
col=dt <<GET column="" names="">200,
column(col[i]) << color cells( "Light Red", Row())
)
)));
//Does not work - it needs to be an exact match
c="FOB";
b={"3"};//trying to look for cells in columns labelled with FOB whihc contains the character '3'
For(i=1,i<=nc,i++, if( Contains( col[i], c ),
for each row(
If( contains(b,as column(col[i])),
column(col[i])<< color cells( "Light Red", Row())
)
)));
wait (2);
//Works when specifying exactly the content of the cell(s) to match
c="FOB";
b={"1,1,2,1,1,2,3,3"};
For(i=1,i<=nc,i++, if( Contains( col[i], c ),
for each row(
If( contains(b,as column(col[i])),
column(col[i])<< color cells( "Red", Row())
)
)));
</GET>数据表脚本编写回复:使用“for each row”和嵌套“for”循环的条件格式(颜色)问题您正在向后指定您的 Contains() 函数,并且您正在比较 JMP 列表。修复这些,它工作正常。

Names Default To Here( 1 );
clear log();
dt = New Table( "test",
Add Rows( 8 ),
New Column( "unique_group_id",
Character,
"Nominal",
Set Values(
{"ELN-19-0588-A", "ELN-19-0588-B", "ELN-19-0588-C", "ELN-19-0588-D",
"ELN-19-0588-E", "ELN-19-0588-F", "ELN-19-0588-G", "ELN-19-0588-H"}
),
Set Display Width( 115 )
),
New Column( "FOB max",
Character,
"Nominal",
Set Selected,
Set Values(
{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
"0,0,3,0,0,1,0,2", "1,1,2,1,1,2,3,3", "0,0,0,0,0,0,0,0",
"4,2,2,3,2,3,3,4", "1,0,0,1,1,1,1,1"}
)
),
New Column( "glib1 % PBS - potatoe",
Numeric,
"Ordinal",
Format( "Best", 12 ),
Set Selected,
Set Values( [100, 113.39, 108.3, 156.38, 822.21, 768.51, 487.2, 222.56] )
),
New Column( "calb (IHC) cere",
Character,
"Nominal",
Set Values(
{"0,0,0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0", "0,0,0,0,0,0,0,0",
"0,0,0,0,0,0,0,0", "3,4,3,4,3,3,3,4", "3,3,3,5,2,3,3,3",
"0,0,0,0,0,0,0,0", "0,0,0,0,0,0,1,0"}
)
)
);
wait(2);
col=dt <<GET column="" names="">200,
column(col[i]) << color cells( "Light Red", Row())
)
)));
//Does not work - it needs to be an exact match
c = "FOB";
b = "3";//trying to look for cells in columns labelled with FOB whihc contains the character '3'
For( i = 1, i <= nc, i++,
If( Contains( col[i], c ),
For Each Row(
If( Contains( As Column( col[i] ), b ),
Column( col[i] ) << color cells( "Light Red", Row() )
);
)
)
);
wait (2);
//Works when specifying exactly the content of the cell(s) to match
c = "FOB";
b = "1,1,2,1,1,2,3,3";
For( i = 1, i <= nc, i++,
If( Contains( col[i], c ),
For Each Row(
If( Contains( As Column( col[i] ), b ),
Column( col[i] ) << color cells( "Red", Row() )
)
)
)
);</GET>
回复:使用“for each row”和嵌套“for”循环的条件格式(颜色)问题你好,
更改您的代码以匹配下面代码中的第 67 行。
根据您提供的参数,包含 ( ) 可以让您做一些不同的事情。 例如:
包含 ( {"cat", "dog", "mouse", "dog", "horse"}, "dog" ) 返回 2,因为提供的列表中第一次出现的 "dog" 位于位置 2。
包含 ({"cattle", "dog", "mouse"}, "cat") 返回 0,因为列表中没有出现“cat”。 如果我们想逐个元素搜索列表以查看“cat”是否是任何元素的子字符串,我们必须遍历列表。
您的原始代码有点像最后一个示例:Contains (b, :col) 检查列单元格值是否与 b 中的任何元素匹配,您已将其定义为 {"3"}。 未找到匹配项。
相反,新代码 Contains(:col, b[1]) 检查 b[1](列表 b 的第一个元素“3”)是否包含在列单元格值中。 以这种方式使用, Contains (<>, <>) 函数在字符串 <> 中查找子字符串 <> -- 我相信这是您想要的。
干杯,
布雷迪
包含 ({"cat", "dog", "mouse"}, "cat") 返回
