使用“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”循环的条件格式(颜色)问题谢谢!回复:使用“for each row”和嵌套“for”循环的条件格式(颜色)问题你好,
更改您的代码以匹配下面代码中的第 67 行。
Contains ( ) 可以让你做一些不同的事情,这取决于你提供的参数。 例如:
Contains ( {"cat", "dog", "mouse", "dog", "horse"}, "dog" ) 返回 2,因为提供的列表中第一次出现的 "dog" 位于位置 2。
Contains ({"cattle", "dog", "mouse"}, "cat") 返回 0,因为列表中没有出现 "cat"。 如果我们想逐个元素搜索列表以查看“cat”是否是任何元素的子字符串,我们必须遍历列表。
您的原始代码有点像最后一个示例:Contains (b, :col) 检查列单元格值是否与 b 中定义为 {"3"} 的任何元素匹配。 未找到匹配项。
相反,新代码 Contains(:col, b[1]) 检查列单元格值中是否包含列表 b 的第一个元素 b[1],即“3”。 以这种方式使用时,Contains (<>, <>) 函数会在字符串 <> 中查找子字符串 <>——我相信这就是您想要的。
干杯,
布雷迪
包含 ({"cat", "dog", "mouse"}, "cat") 返回

回复:使用“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>