mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 21:33:16 +00:00
Better checks and more choice in Conditional formatting
This commit is contained in:
@@ -78,30 +78,50 @@
|
|||||||
[Parameter(ParameterSetName = "FiveIconSet")]
|
[Parameter(ParameterSetName = "FiveIconSet")]
|
||||||
[Parameter(ParameterSetName = "FiveIconSetAddress")]
|
[Parameter(ParameterSetName = "FiveIconSetAddress")]
|
||||||
[switch]$Reverse,
|
[switch]$Reverse,
|
||||||
#A value for the condition (e.g. "2000" if the test is 'lessthan 2000')
|
#A value for the condition (e.g. 2000 if the test is 'lessthan 2000' ; Formulas should begin with "=" )
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[string]$ConditionValue,
|
[string]$ConditionValue,
|
||||||
#A second value for the conditions like "between x and Y"
|
#A second value for the conditions like "between x and Y"
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[string]$ConditionValue2,
|
[string]$ConditionValue2,
|
||||||
#Background colour for matching items
|
#Background colour for matching items
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[System.Drawing.Color]$BackgroundColor,
|
[System.Drawing.Color]$BackgroundColor,
|
||||||
#Background pattern for matching items
|
#Background pattern for matching items
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::None ,
|
[OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::None ,
|
||||||
#Secondary colour when a background pattern requires it
|
#Secondary colour when a background pattern requires it
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[System.Drawing.Color]$PatternColor,
|
[System.Drawing.Color]$PatternColor,
|
||||||
#Sets the numeric format for matching items
|
#Sets the numeric format for matching items
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
$NumberFormat,
|
$NumberFormat,
|
||||||
#Put matching items in bold face
|
#Put matching items in bold face
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[switch]$Bold,
|
[switch]$Bold,
|
||||||
#Put matching items in italic
|
#Put matching items in italic
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[switch]$Italic,
|
[switch]$Italic,
|
||||||
#Underline matching items
|
#Underline matching items
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[switch]$Underline,
|
[switch]$Underline,
|
||||||
#Strikethrough text of matching items
|
#Strikethrough text of matching items
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||||
|
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||||
[switch]$StrikeThru,
|
[switch]$StrikeThru,
|
||||||
#If specified pass the rule back to the caller to allow additional customization.
|
#If specified pass the rule back to the caller to allow additional customization.
|
||||||
[switch]$Passthru
|
[switch]$Passthru
|
||||||
)
|
)
|
||||||
|
|
||||||
#Allow conditional formatting to work like Set-Format (with single ADDRESS parameter), split it to get worksheet and range of cells.
|
#Allow conditional formatting to work like Set-Format (with single ADDRESS parameter), split it to get worksheet and range of cells.
|
||||||
If ($Address -and -not $WorkSheet -and -not $Range) {
|
If ($Address -and -not $WorkSheet -and -not $Range) {
|
||||||
$WorkSheet = $Address.Worksheet[0]
|
$WorkSheet = $Address.Worksheet[0]
|
||||||
@@ -116,22 +136,47 @@
|
|||||||
if ($PSBoundParameters.ContainsKey("Reverse" ) ) {$rule.reverse = [boolean]$Reverse}
|
if ($PSBoundParameters.ContainsKey("Reverse" ) ) {$rule.reverse = [boolean]$Reverse}
|
||||||
#endregion
|
#endregion
|
||||||
#region set the rule conditions
|
#region set the rule conditions
|
||||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
#for lessThan/GreaterThan/Equal/Between conditions make sure that strings are wrapped in quotes. Formulas should be passed with = which will be stripped.
|
||||||
|
if ($RuleType -match "Than|Equal|Between" ) {
|
||||||
|
if ($ConditionValue) {
|
||||||
|
$number = $Null
|
||||||
|
if ([Double]::TryParse($ConditionValue, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) ) {
|
||||||
|
$ConditionValue = $number
|
||||||
|
}
|
||||||
|
elseif (($ConditionValue -notmatch '^=') -and ($ConditionValue -notmatch '^".*"$') ) {
|
||||||
|
$ConditionValue = '"' + $ConditionValue +'"'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($ConditionValue2) {
|
||||||
|
$number = $Null
|
||||||
|
if ([Double]::TryParse($ConditionValue2, [System.Globalization.NumberStyles]::Any, [System.Globalization.NumberFormatInfo]::CurrentInfo, [Ref]$number) ) {
|
||||||
|
$ConditionValue2 = $number
|
||||||
|
}
|
||||||
|
elseif (($ConditionValue2 -notmatch '^=') -and ($ConditionValue2 -notmatch '^".*"$') ) {
|
||||||
|
$ConditionValue2 = '"' + $ConditionValue2 + '"'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#But we don't usually want quotes round containstext | beginswith type rules. Can't be Certain they need to be removed, so warn the user their condition might be wrong
|
||||||
|
if ($RuleType -match "Text|With" -and $ConditionValue -match '^".*"$' ) {
|
||||||
|
Write-Warning -Message "The condition will look for the quotes at the start and end."
|
||||||
|
}
|
||||||
|
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$RuleType -match "Top|Botom" ) {$rule.Rank = $ConditionValue }
|
$RuleType -match "Top|Botom" ) {$rule.Rank = $ConditionValue }
|
||||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$RuleType -match "StdDev" ) {$rule.StdDev = $ConditionValue }
|
$RuleType -match "StdDev" ) {$rule.StdDev = $ConditionValue }
|
||||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$RuleType -match "Than|Equal|Expression" ) {$rule.Formula = ($ConditionValue -replace '^=','') }
|
$RuleType -match "Than|Equal|Expression" ) {$rule.Formula = ($ConditionValue -replace '^=','') }
|
||||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$RuleType -match "Text|With" ) {$rule.Text = ($ConditionValue -replace '^=','') }
|
$RuleType -match "Text|With" ) {$rule.Text = ($ConditionValue -replace '^=','') }
|
||||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$PSBoundParameters.ContainsKey("ConditionValue") -and
|
$PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||||
$RuleType -match "Between" ) {
|
$RuleType -match "Between" ) {
|
||||||
$rule.Formula = ($ConditionValue -replace '^=','');
|
$rule.Formula = ($ConditionValue -replace '^=','');
|
||||||
$rule.Formula2 = ($ConditionValue2 -replace '^=','')
|
$rule.Formula2 = ($ConditionValue2 -replace '^=','')
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#region set the rule format
|
#region set the rule format
|
||||||
if ($PSBoundParameters.ContainsKey("NumberFormat" ) ) {$rule.Style.NumberFormat.Format = (Expand-NumberFormat $NumberFormat) }
|
if ($PSBoundParameters.ContainsKey("NumberFormat" ) ) {$rule.Style.NumberFormat.Format = (Expand-NumberFormat $NumberFormat) }
|
||||||
if ($Underline ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::Single }
|
if ($Underline ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::Single }
|
||||||
elseif ($PSBoundParameters.ContainsKey("Underline" ) ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::None }
|
elseif ($PSBoundParameters.ContainsKey("Underline" ) ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::None }
|
||||||
@@ -142,7 +187,7 @@
|
|||||||
if ($PSBoundParameters.ContainsKey("BackgroundColor" ) ) {$rule.Style.Fill.BackgroundColor.color = $BackgroundColor }
|
if ($PSBoundParameters.ContainsKey("BackgroundColor" ) ) {$rule.Style.Fill.BackgroundColor.color = $BackgroundColor }
|
||||||
if ($PSBoundParameters.ContainsKey("BackgroundPattern") ) {$rule.Style.Fill.PatternType = $BackgroundPattern }
|
if ($PSBoundParameters.ContainsKey("BackgroundPattern") ) {$rule.Style.Fill.PatternType = $BackgroundPattern }
|
||||||
if ($PSBoundParameters.ContainsKey("PatternColor" ) ) {$rule.Style.Fill.PatternColor.color = $PatternColor }
|
if ($PSBoundParameters.ContainsKey("PatternColor" ) ) {$rule.Style.Fill.PatternColor.color = $PatternColor }
|
||||||
#endregion
|
#endregion
|
||||||
#Allow further tweaking by returning the rule, if passthru specified
|
#Allow further tweaking by returning the rule, if passthru specified
|
||||||
if ($Passthru) {$rule}
|
if ($Passthru) {$rule}
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,16 @@ function New-ConditionalText {
|
|||||||
[String]$Range,
|
[String]$Range,
|
||||||
[OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
|
[OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
|
||||||
[ValidateSet(
|
[ValidateSet(
|
||||||
"LessThan","LessThanOrEqual","GreaterThan","GreaterThanOrEqual",
|
"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual",
|
||||||
"NotEqual","Equal","ContainsText","NotContainsText","BeginsWith","EndsWith",
|
"Equal", "NotEqual",
|
||||||
"Last7Days","LastMonth","LastWeek",
|
"Top", "TopPercent", "Bottom", "BottomPercent",
|
||||||
"NextMonth","NextWeek",
|
"ContainsText", "NotContainsText", "BeginsWith", "EndsWith",
|
||||||
"ThisMonth","ThisWeek",
|
"ContainsBlanks", "NotContainsBlanks", "ContainsErrors", "NotContainsErrors",
|
||||||
"Today","Tomorrow","Yesterday",
|
"DuplicateValues", "UniqueValues",
|
||||||
"DuplicateValues",
|
"Tomorrow", "Today", "Yesterday", "Last7Days",
|
||||||
"AboveOrEqualAverage","BelowAverage","AboveAverage",
|
"NextWeek", "ThisWeek", "LastWeek",
|
||||||
"Top", "TopPercent", "ContainsBlanks"
|
"NextMonth", "ThisMonth", "LastMonth",
|
||||||
|
"AboveAverage", "AboveOrEqualAverage", "BelowAverage", "BelowOrEqualAverage"
|
||||||
)]
|
)]
|
||||||
$ConditionalType="ContainsText"
|
$ConditionalType="ContainsText"
|
||||||
)
|
)
|
||||||
@@ -23,13 +24,13 @@ function New-ConditionalText {
|
|||||||
$obj = [PSCustomObject]@{
|
$obj = [PSCustomObject]@{
|
||||||
Text = $Text
|
Text = $Text
|
||||||
ConditionalTextColor = $ConditionalTextColor
|
ConditionalTextColor = $ConditionalTextColor
|
||||||
ConditionalType = $ConditionalType
|
ConditionalType = $ConditionalType
|
||||||
PatternType = $PatternType
|
PatternType = $PatternType
|
||||||
Range = $Range
|
Range = $Range
|
||||||
BackgroundColor = $BackgroundColor
|
BackgroundColor = $BackgroundColor
|
||||||
}
|
}
|
||||||
|
|
||||||
$obj.pstypenames.Clear()
|
$obj.pstypenames.Clear()
|
||||||
$obj.pstypenames.Add("ConditionalText")
|
$obj.pstypenames.Add("ConditionalText")
|
||||||
$obj
|
$obj
|
||||||
}
|
}
|
||||||
12
README.md
12
README.md
@@ -51,7 +51,17 @@ Install-Module ImportExcel -scope CurrentUser
|
|||||||
```PowerShell
|
```PowerShell
|
||||||
Install-Module ImportExcel
|
Install-Module ImportExcel
|
||||||
```
|
```
|
||||||
# New to Aug 16th
|
|
||||||
|
- Moved PivotTable Functions out of Export-Excel.PS1 into their own file and moved Add-ExcelChart out of Export-Excel.ps1 into New-ExcelChart.ps1
|
||||||
|
- in Export-Excel there is better checking of Table and PivotTable names (for uniqueness) and a new test in quick charts that there is suitable data for charting.
|
||||||
|
- in New-ConditionalText, more types of conditional format are supported, and conditionalTextColor has an argument completer
|
||||||
|
- in Add-ConditionalFormatting: improved parameter intellisense and now wrap those strings which need it in quotes (for = <= >= string needs to be in double quotes)
|
||||||
|
- in New-ExcelChartDefinition: Legend parameters (for size, bold & position ) are now supported
|
||||||
|
- Add-ExcelChart now supports -PassThru to return the chart for tweaking after creation; there is now a -PivotTable parameter to allow Add-PivotTable to call the code in Add-ExcelChart
|
||||||
|
- in Add-PivotTable: chart creation has been moved out to Add-ExcelChart. -PassThru returns the pivot table (e.g. to allow names /sort orders of data series to be tweaked ) -Address parameter allows Pivot to be placed on an existing sheet; -PivotTableStyle allows a change from "Medium6", -PivotNumberFormat sets data cells and -PivotChartDefinition allows a defintion created with New-ExcelChartDefinition to be used. This opens up all the things that Add-Excel chart can do without duplicating the parameters on Add-Pivot table and Export-Excel. Definition, TableStyle, Numberformat and ChartDefiniton can be used in New-PivotTableDefinition .
|
||||||
|
-
|
||||||
|
|
||||||
|
# What's new in Release 5.2
|
||||||
- Value does not need to be mandatory in Set-Row or Set-Column, also tidied their parameters a little.
|
- Value does not need to be mandatory in Set-Row or Set-Column, also tidied their parameters a little.
|
||||||
- Added support for array formulas in Set-Format (it really should be set range now that it sets values, formulas and hyperlinks - that can go on the to-do list )
|
- Added support for array formulas in Set-Format (it really should be set range now that it sets values, formulas and hyperlinks - that can go on the to-do list )
|
||||||
- Fixed a bug with -Append in Export-Excel which caused it to overwrite the last row if the new data was a simple type.
|
- Fixed a bug with -Append in Export-Excel which caused it to overwrite the last row if the new data was a simple type.
|
||||||
|
|||||||
18
ToDo.md
18
ToDo.md
@@ -1,19 +1,11 @@
|
|||||||
- [x] Create an autocomplete for WorkSheetName param on ImportExcel and for number format ; where number format exists Translate "Date", "DateTime", "Currency"
|
- [X] Add -PivotTableSource parameter to Add-ExcelChart.
|
||||||
- [x] Support "make worksheet active"
|
- [X] Refactor Add-PivotTable to use Add-ExcelChart rather duplicating code. Add support for -ExcelChartDefinition support for all chart params ??
|
||||||
- [X] Add checks for valid worksheet names
|
- [X] Add -Passthru to Add-ExcelChart and Add-PivotTable
|
||||||
- [x] Allow Exclude property to take wildcards
|
- [X] Add support for PivotTable number format, data field name and possibly sort. -
|
||||||
- [ ] Improve checking of worksheet, pivot names, range names and table names
|
- [ ] Improve checking of worksheet, pivot names, range names and table names
|
||||||
- [ ] Investigate regional support for number conversion & possible date conversion. Also investigate feasablity of preserving number format when converting string to number
|
- [ ] Investigate regional support for number conversion & possible date conversion. Also investigate feasablity of preserving number format when converting string to number
|
||||||
- [ ] Add help text for parmaters which don't have it ( PivotDataToColumn , NoClobber and CellStyleSB ) in Export Excel, copy to Send-SQLDataToExcel
|
- [ ] Add help text for parmaters which don't have it ( PivotDataToColumn , NoClobber and CellStyleSB ) in Export Excel, copy to Send-SQLDataToExcel
|
||||||
- [ ] Add help in ConvertToExcelXLSx.ps1, Get-HTMLTable.ps1, GetRange.PS1, GetExcelTable.Ps1, Import-HTML.PS1, New-ConditionalFormattingIconSet.Ps1, NewConditionalText.PS1, New-Psitem.PS1, Remove-Worksheet.ps1 and Add-ExcelChart - Copy parameter help from function Add-ExcelChart into New-ExcelChart.ps1
|
- [ ] Add help in ConvertToExcelXLSx.ps1, Get-HTMLTable.ps1, GetRange.PS1, GetExcelTable.Ps1, Import-HTML.PS1, New-ConditionalFormattingIconSet.Ps1, NewConditionalText.PS1, New-Psitem.PS1, Remove-Worksheet.ps1 and Add-ExcelChart - Copy parameter help from function Add-ExcelChart into New-ExcelChart.ps1
|
||||||
- [ ] Add examples to add-ConditionalFormat, set-format,set-Row and Set-column (e.g. from tests)
|
- [ ] Add examples to add-ConditionalFormat, set-format,set-Row and Set-column (e.g. from tests)
|
||||||
- [ ] Add Examples and tests for new "Quick charts" in Export Excel (replace examples) that use Charting.ps1, GetXYRange.ps1, InferData.PS1 (move these to deprecated).
|
- [ ] Add Examples and tests for new "Quick charts" in Export Excel (replace examples) that use Charting.ps1, GetXYRange.ps1, InferData.PS1 (move these to deprecated).
|
||||||
- [X] Test password behaviour in Export-Excel Open & Close-Excel Package
|
|
||||||
- [X] Test Add PivotTable selecting source sheet by position
|
|
||||||
-[X] Test UnhideSheet, and Wildcard support for hideSheet
|
|
||||||
- [X] Test return range support for Set-Row
|
|
||||||
- [X] Test return range support for Set-Column
|
|
||||||
- [X] Test Expand-NumberFormat.
|
|
||||||
- [X] Test Set-Row and Set-column setting values as dates and hyperlinks (only testing Column)
|
|
||||||
- [X] Increase Test code covereage for Set-Format
|
|
||||||
- [ ] Increase Test code covereage for import-excel
|
- [ ] Increase Test code covereage for import-excel
|
||||||
Reference in New Issue
Block a user