使用“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”循環的條件格式(顏色)問題您正在向後指定您的 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”循環的條件格式(顏色)問題你好,
更改您的代碼以匹配下面代碼中的第 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") 返回
