mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Add scriptblock for Cell Fill Style
This commit is contained in:
19
Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1
Normal file
19
Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Examples/FormatCellStyles/PassInScriptBlock.ps1
Normal file
15
Examples/FormatCellStyles/PassInScriptBlock.ps1
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
$RandomStyle = {
|
||||||
|
param(
|
||||||
|
$workSheet,
|
||||||
|
$totalRows,
|
||||||
|
$lastColumn
|
||||||
|
)
|
||||||
|
|
||||||
|
2..$totalRows | ForEach-Object{
|
||||||
|
Set-CellStyle $workSheet $_ $LastColumn Solid (Write-Output LightGreen Gray Red|Get-Random)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Get-Process |
|
||||||
|
Select-Object Company,Handles,PM, NPM|
|
||||||
|
Export-Excel $xlfile -Show -AutoSize -CellStyleSB $RandomStyle
|
||||||
@@ -51,6 +51,8 @@ function Export-Excel {
|
|||||||
[Object[]]$ConditionalFormat,
|
[Object[]]$ConditionalFormat,
|
||||||
[Object[]]$ConditionalText,
|
[Object[]]$ConditionalText,
|
||||||
[Object[]]$ExcelChartDefinition,
|
[Object[]]$ExcelChartDefinition,
|
||||||
|
# [Object[]]$CellStyle,
|
||||||
|
[ScriptBlock]$CellStyleSB,
|
||||||
[string[]]$HideSheet,
|
[string[]]$HideSheet,
|
||||||
[Switch]$KillExcel,
|
[Switch]$KillExcel,
|
||||||
[Switch]$AutoNameRange,
|
[Switch]$AutoNameRange,
|
||||||
@@ -408,6 +410,12 @@ function Export-Excel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($CellStyleSB) {
|
||||||
|
$TotalRows=$ws.Dimension.Rows
|
||||||
|
$LastColumn=(Get-ExcelColumnName $ws.Dimension.Columns).ColumnName
|
||||||
|
& $CellStyleSB $ws $TotalRows $LastColumn
|
||||||
|
}
|
||||||
|
|
||||||
if($PassThru) {
|
if($PassThru) {
|
||||||
$pkg
|
$pkg
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
|
|||||||
. $PSScriptRoot\Get-Range.ps1
|
. $PSScriptRoot\Get-Range.ps1
|
||||||
. $PSScriptRoot\TrackingUtils.ps1
|
. $PSScriptRoot\TrackingUtils.ps1
|
||||||
. $PSScriptRoot\Copy-ExcelWorkSheet.ps1
|
. $PSScriptRoot\Copy-ExcelWorkSheet.ps1
|
||||||
|
. $PSScriptRoot\Set-CellStyle.ps1
|
||||||
|
|
||||||
if($PSVersionTable.PSVersion.Major -ge 5) {
|
if($PSVersionTable.PSVersion.Major -ge 5) {
|
||||||
. $PSScriptRoot\plot.ps1
|
. $PSScriptRoot\plot.ps1
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ $fileList = echo `
|
|||||||
Get-Range.ps1 `
|
Get-Range.ps1 `
|
||||||
TrackingUtils.ps1 `
|
TrackingUtils.ps1 `
|
||||||
Copy-ExcelWorkSheet.ps1 `
|
Copy-ExcelWorkSheet.ps1 `
|
||||||
|
Set-CellStyle.ps1 `
|
||||||
plot.ps1
|
plot.ps1
|
||||||
|
|
||||||
if ('' -eq $InstallDirectory)
|
if ('' -eq $InstallDirectory)
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ $targetFiles = echo `
|
|||||||
Get-Range.ps1 `
|
Get-Range.ps1 `
|
||||||
TrackingUtils.ps1 `
|
TrackingUtils.ps1 `
|
||||||
Copy-ExcelWorkSheet.ps1 `
|
Copy-ExcelWorkSheet.ps1 `
|
||||||
|
Set-CellStyle.ps1 `
|
||||||
plot.ps1
|
plot.ps1
|
||||||
|
|
||||||
ls $targetFiles |
|
ls $targetFiles |
|
||||||
|
|||||||
13
Set-CellStyle.ps1
Normal file
13
Set-CellStyle.ps1
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
function Set-CellStyle {
|
||||||
|
param(
|
||||||
|
$WorkSheet,
|
||||||
|
$Row,
|
||||||
|
$LastColumn,
|
||||||
|
[OfficeOpenXml.Style.ExcelFillStyle]$Pattern,
|
||||||
|
[System.Drawing.Color]$Color
|
||||||
|
)
|
||||||
|
|
||||||
|
$t=$WorkSheet.Cells["A$($Row):$($LastColumn)$($Row)"]
|
||||||
|
$t.Style.Fill.PatternType=$Pattern
|
||||||
|
$t.Style.Fill.BackgroundColor.SetColor($Color)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user