From 1b2c280e4b03552c6d3082bf9772a45119c78fe0 Mon Sep 17 00:00:00 2001 From: Wyatt Wong Date: Mon, 5 Feb 2024 16:36:17 +0800 Subject: [PATCH 1/2] Create ConditionalFormattingUnmatchColumns.ps1 --- .../ConditionalFormattingUnmatchColumns.ps1 | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 diff --git a/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 new file mode 100644 index 0000000..1f4fff9 --- /dev/null +++ b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 @@ -0,0 +1,26 @@ +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 + +$cfi1 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$D$2:$D$1048576' -ConditionValue '=NOT(EXACT($A2,$D2))' -RuleType Expression -ForegroundColor Red +$cfi2 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$E$2:$E$1048576' -ConditionValue '=NOT(EXACT($B2,$E2))' -RuleType Expression -ForegroundColor Red +$cfi3 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$F$2:$F$1048576' -ConditionValue '=NOT(EXACT($C2,$F2))' -RuleType Expression -ForegroundColor Red + +Close-ExcelPackage $file -Show From d251e7070a988f818477e427670e2c65aa1e0008 Mon Sep 17 00:00:00 2001 From: Wyatt Wong Date: Tue, 6 Feb 2024 10:04:44 +0800 Subject: [PATCH 2/2] Update and rename ConditionalFormattingUnmatchColumns.ps1 to ConditionalFormattingUnmatchColumns-Sol1.ps1 Minor update and change the filename as Solution 1 --- ...mns.ps1 => ConditionalFormattingUnmatchColumns-Sol1.ps1} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Examples/ConditionalFormatting/{ConditionalFormattingUnmatchColumns.ps1 => ConditionalFormattingUnmatchColumns-Sol1.ps1} (59%) diff --git a/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol1.ps1 similarity index 59% rename from Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 rename to Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol1.ps1 index 1f4fff9..8762da9 100644 --- a/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns.ps1 +++ b/Examples/ConditionalFormatting/ConditionalFormattingUnmatchColumns-Sol1.ps1 @@ -19,8 +19,8 @@ Remove-Item $xlfile -ErrorAction SilentlyContinue $file = $data | Export-Excel $xlfile -AutoSize -PassThru -$cfi1 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$D$2:$D$1048576' -ConditionValue '=NOT(EXACT($A2,$D2))' -RuleType Expression -ForegroundColor Red -$cfi2 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$E$2:$E$1048576' -ConditionValue '=NOT(EXACT($B2,$E2))' -RuleType Expression -ForegroundColor Red -$cfi3 = Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$F$2:$F$1048576' -ConditionValue '=NOT(EXACT($C2,$F2))' -RuleType Expression -ForegroundColor Red +Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$D$2:$D$1048576' -ConditionValue '=NOT(EXACT($A2,$D2))' -RuleType Expression -ForegroundColor Red +Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$E$2:$E$1048576' -ConditionValue '=NOT(EXACT($B2,$E2))' -RuleType Expression -ForegroundColor Red +Add-ConditionalFormatting -Worksheet $file.sheet1 -Range '$F$2:$F$1048576' -ConditionValue '=NOT(EXACT($C2,$F2))' -RuleType Expression -ForegroundColor Red Close-ExcelPackage $file -Show