Merge pull request #1208 from kkazala/kkazala/exportformatting

Kkazala/exportformatting
This commit is contained in:
Doug Finke
2022-07-13 12:09:55 -04:00
committed by GitHub
3 changed files with 23 additions and 2 deletions

View File

@@ -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

View File

@@ -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