Files
ImportExcel/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1
2019-11-18 07:50:20 +00:00

23 lines
695 B
PowerShell

try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
$xlfile = "$env:temp\testFmt.xlsx"
Get-Process |
Select-Object Company,Handles,PM, NPM|
Export-Excel $xlfile -Show -AutoSize -CellStyleSB {
param(
$workSheet,
$totalRows,
$lastColumn
)
Set-CellStyle $workSheet 1 $LastColumn Solid Cyan
foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 0})) {
Set-CellStyle $workSheet $row $LastColumn Solid Gray
}
foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 1})) {
Set-CellStyle $workSheet $row $LastColumn Solid LightGray
}
}