diff --git a/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 b/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 new file mode 100644 index 0000000..e123fc8 --- /dev/null +++ b/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 @@ -0,0 +1,21 @@ +try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return} + +# This example is using Excel generated by Highlight-DiffCells.ps1 +# The displayed rule should be the same as in the PS script + +function Get-ConditionalFormatting { + param ( + [string] $xlSourcefile + ) + $excel = Open-ExcelPackage -Path $xlSourcefile + + $excel.Workbook.Worksheets | ForEach-Object { + $wsNme = $_.Name + $_.ConditionalFormatting | ForEach-Object { + "Add-ConditionalFormatting -Worksheet `$excel[""$wsNme""] -Range '$($_.Address)' -ConditionValue '=$($_.Formula)' -RuleType $($_.Type) " + } + } +} + +$xlSourcefile = "$PSScriptRoot\GetConditionalFormatting.xlsx" +Get-ConditionalFormatting -xlSourcefile $xlSourcefile \ No newline at end of file diff --git a/Examples/ConditionalFormatting/GetConditionalFormatting.xlsx b/Examples/ConditionalFormatting/GetConditionalFormatting.xlsx new file mode 100644 index 0000000..bfa1cba Binary files /dev/null and b/Examples/ConditionalFormatting/GetConditionalFormatting.xlsx differ diff --git a/Examples/ConditionalFormatting/Highlight-DiffCells.ps1 b/Examples/ConditionalFormatting/Highlight-DiffCells.ps1 index 4cbffac..29f90a6 100644 --- a/Examples/ConditionalFormatting/Highlight-DiffCells.ps1 +++ b/Examples/ConditionalFormatting/Highlight-DiffCells.ps1 @@ -1,6 +1,5 @@ try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return } -# Get rid of pre-exisiting sheet $xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" Write-Verbose -Verbose -Message "Save location: $xlSourcefile" @@ -21,6 +20,7 @@ South,Delaware,712,508 $excel = $data | Export-Excel $xlSourcefile -AutoSize -PassThru -Add-ConditionalFormatting -Worksheet $excel.sheet1 -Range "C2:C10" -ConditionValue '=C2=D2' -RuleType Expression -BackgroundColor Cyan +Add-ConditionalFormatting -Worksheet $excel.sheet1 -Range "C2:D10" -ConditionValue '=$C2=$D2' -RuleType Expression -BackgroundColor ([System.Drawing.Color]::Thistle) -Bold +Add-ConditionalFormatting -Worksheet $excel.sheet1 -Range "A2:D10" -ConditionValue '=$C2=$D2' -RuleType Expression -BackgroundColor ([System.Drawing.Color]::LavenderBlush) Close-ExcelPackage $excel -Show \ No newline at end of file