From b8872ef6b450aef57c493a90c9d47ad271489c8b Mon Sep 17 00:00:00 2001 From: Wyatt Wong Date: Tue, 6 Feb 2024 10:07:08 +0800 Subject: [PATCH 1/2] Create ConditionalFormattingUnmatchColumns-Sol2.ps1 Added Conditional Formatting Unmatch Columns Solution 2 --- ...nditionalFormattingUnmatchColumns-Sol2.ps1 | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol2.ps1 diff --git a/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol2.ps1 b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol2.ps1 new file mode 100644 index 00000000..f5d5bc4f --- /dev/null +++ b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol2.ps1 @@ -0,0 +1,27 @@ +try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return } + +$data = ConvertFrom-Csv @" +Sequence1,StateName1,Abbreviation1,Sequence2,StateName2,Abbreviation2 +A001,Alabama,AL,A001,Alabama,AL +A002,California,CA,B002,California,CA +A003,Colorado,CO,A003,Colorado,CO +A004,Florida,FL,A004,Maine,FL +A005,Missouri,MO,A005,Missouri,MI +A006,New Mexico,NM,A006,Tennessee,TN +A007,North Carolina,NC,C007,North Carolina,NC +A008,North Dakota,ND,A008,South Dakota,SD +A009,Rhode Island,RI,D009,Rhode Island,VA +A010,Texas,TX,A010,Texas,TX +"@ + +$xlfile = "$PSScriptRoot\test.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$file = $data | Export-Excel $xlfile -AutoSize -PassThru + +Add-ConditionalFormatting -Worksheet $file.Sheet1 -Range '$1:$1' -ConditionValue '=True' -RuleType Expression -StopIfTrue +Add-ConditionalFormatting -Worksheet $file.Sheet1 -Range '$D:$D' -ConditionValue '=NOT(EXACT($A1,$D1))' -RuleType Expression -ForegroundColor Red +Add-ConditionalFormatting -Worksheet $file.Sheet1 -Range '$E:$E' -ConditionValue '=NOT(EXACT($B1,$E1))' -RuleType Expression -ForegroundColor Red +Add-ConditionalFormatting -Worksheet $file.Sheet1 -Range '$F:$F' -ConditionValue '=NOT(EXACT($C1,$F1))' -RuleType Expression -ForegroundColor Red + +Close-ExcelPackage $file -Show From 5a606f4f29cec9208a6744649b66972a78f40660 Mon Sep 17 00:00:00 2001 From: Wyatt Wong Date: Tue, 6 Feb 2024 10:49:52 +0800 Subject: [PATCH 2/2] Update ConditionalFormattingUnmatchColumns-Sol2.ps1