mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Implemented conditional text formatting
This commit is contained in:
@@ -45,8 +45,7 @@ function Export-Excel {
|
||||
[string]$TableName,
|
||||
[OfficeOpenXml.Table.TableStyles]$TableStyle="Medium6",
|
||||
[Object[]]$ConditionalFormat,
|
||||
[string]$ConditionalText,
|
||||
[System.Drawing.Color]$ConditionalTextColor="Red",
|
||||
[Object[]]$ConditionalText,
|
||||
[Object[]]$ExcelChartDefinition,
|
||||
[string[]]$HideSheet,
|
||||
[Switch]$KillExcel,
|
||||
@@ -338,10 +337,17 @@ function Export-Excel {
|
||||
}
|
||||
}
|
||||
|
||||
if($ConditionalText) {
|
||||
$rule=$ws.Cells[$ws.Dimension.Address].ConditionalFormatting.AddContainsText();
|
||||
$rule.Text = $ConditionalText
|
||||
$rule.Style.Font.Color.Color = $ConditionalTextColor
|
||||
if($ConditionalText) {
|
||||
foreach ($targetConditionalText in $ConditionalText) {
|
||||
$target = "Add$($targetConditionalText.ConditionalType)"
|
||||
|
||||
$rule=($ws.Cells[$ws.Dimension.Address].ConditionalFormatting).$target()
|
||||
$rule.Text = $targetConditionalText.Text
|
||||
$rule.Style.Font.Color.Color = $targetConditionalText.ConditionalTextColor
|
||||
|
||||
$rule.Style.Fill.PatternType=$targetConditionalText.PatternType
|
||||
$rule.Style.Fill.BackgroundColor.Color=$targetConditionalText.BackgroundColor
|
||||
}
|
||||
}
|
||||
|
||||
$pkg.Save()
|
||||
|
||||
@@ -2,6 +2,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
|
||||
|
||||
. $PSScriptRoot\Export-Excel.ps1
|
||||
. $PSScriptRoot\New-ConditionalFormattingIconSet.ps1
|
||||
. $PSScriptRoot\New-ConditionalText.ps1
|
||||
. $PSScriptRoot\Export-ExcelSheet.ps1
|
||||
. $PSScriptRoot\New-ExcelChart.ps1
|
||||
. $PSScriptRoot\Invoke-Sum.ps1
|
||||
|
||||
23
New-ConditionalText.ps1
Normal file
23
New-ConditionalText.ps1
Normal file
@@ -0,0 +1,23 @@
|
||||
function New-ConditionalText {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
$Text,
|
||||
[System.Drawing.Color]$ConditionalTextColor="DarkRed",
|
||||
[System.Drawing.Color]$BackgroundColor="LightPink",
|
||||
[OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
|
||||
[ValidateSet("ContainsText","NotContainsText","BeginsWith","EndsWith")]
|
||||
$ConditionalType="ContainsText"
|
||||
)
|
||||
|
||||
$obj = [PSCustomObject]@{
|
||||
Text = $Text
|
||||
ConditionalTextColor = $ConditionalTextColor
|
||||
ConditionalType = $ConditionalType
|
||||
PatternType = $PatternType
|
||||
BackgroundColor = $BackgroundColor
|
||||
}
|
||||
|
||||
$obj.pstypenames.Clear()
|
||||
$obj.pstypenames.Add("ConditionalText")
|
||||
$obj
|
||||
}
|
||||
BIN
images/ConditionalText2.gif
Normal file
BIN
images/ConditionalText2.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
Reference in New Issue
Block a user