From 724ed6b197c345ef906bf85aad616674e8e52989 Mon Sep 17 00:00:00 2001 From: Kinga Kazala Date: Wed, 13 Jul 2022 09:34:30 +0200 Subject: [PATCH] Get-ConditionalFormatting function added --- .../GetConditionalFormatting.ps1 | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 b/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 index 4f2e763..a9bc3a9 100644 --- a/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 +++ b/Examples/ConditionalFormatting/GetConditionalFormatting.ps1 @@ -2,12 +2,20 @@ # This example is using Excel generated by Highlight-DiffCells.ps1 # The displayed rule should be the same as in the PS script -$xlSourcefile = "$env:TEMP.\GetConditionalFormatting.xlsx" -$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) " +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 = "$env:TEMP.\GetConditionalFormatting.xlsx" +Get-ConditionalFormatting -xlSourcefile $xlSourcefile \ No newline at end of file