mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Better checks and more choice in Conditional formatting
This commit is contained in:
@@ -78,25 +78,45 @@
|
||||
[Parameter(ParameterSetName = "FiveIconSet")]
|
||||
[Parameter(ParameterSetName = "FiveIconSetAddress")]
|
||||
[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,
|
||||
#A second value for the conditions like "between x and Y"
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[string]$ConditionValue2,
|
||||
#Background colour for matching items
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[System.Drawing.Color]$BackgroundColor,
|
||||
#Background pattern for matching items
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[OfficeOpenXml.Style.ExcelFillStyle]$BackgroundPattern = [OfficeOpenXml.Style.ExcelFillStyle]::None ,
|
||||
#Secondary colour when a background pattern requires it
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[System.Drawing.Color]$PatternColor,
|
||||
#Sets the numeric format for matching items
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
$NumberFormat,
|
||||
#Put matching items in bold face
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[switch]$Bold,
|
||||
#Put matching items in italic
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[switch]$Italic,
|
||||
#Underline matching items
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[switch]$Underline,
|
||||
#Strikethrough text of matching items
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress")]
|
||||
[switch]$StrikeThru,
|
||||
#If specified pass the rule back to the caller to allow additional customization.
|
||||
[switch]$Passthru
|
||||
@@ -116,6 +136,31 @@
|
||||
if ($PSBoundParameters.ContainsKey("Reverse" ) ) {$rule.reverse = [boolean]$Reverse}
|
||||
#endregion
|
||||
#region set the rule conditions
|
||||
#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 }
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||
|
||||
@@ -7,15 +7,16 @@ function New-ConditionalText {
|
||||
[String]$Range,
|
||||
[OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
|
||||
[ValidateSet(
|
||||
"LessThan","LessThanOrEqual","GreaterThan","GreaterThanOrEqual",
|
||||
"NotEqual","Equal","ContainsText","NotContainsText","BeginsWith","EndsWith",
|
||||
"Last7Days","LastMonth","LastWeek",
|
||||
"NextMonth","NextWeek",
|
||||
"ThisMonth","ThisWeek",
|
||||
"Today","Tomorrow","Yesterday",
|
||||
"DuplicateValues",
|
||||
"AboveOrEqualAverage","BelowAverage","AboveAverage",
|
||||
"Top", "TopPercent", "ContainsBlanks"
|
||||
"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual",
|
||||
"Equal", "NotEqual",
|
||||
"Top", "TopPercent", "Bottom", "BottomPercent",
|
||||
"ContainsText", "NotContainsText", "BeginsWith", "EndsWith",
|
||||
"ContainsBlanks", "NotContainsBlanks", "ContainsErrors", "NotContainsErrors",
|
||||
"DuplicateValues", "UniqueValues",
|
||||
"Tomorrow", "Today", "Yesterday", "Last7Days",
|
||||
"NextWeek", "ThisWeek", "LastWeek",
|
||||
"NextMonth", "ThisMonth", "LastMonth",
|
||||
"AboveAverage", "AboveOrEqualAverage", "BelowAverage", "BelowOrEqualAverage"
|
||||
)]
|
||||
$ConditionalType="ContainsText"
|
||||
)
|
||||
|
||||
12
README.md
12
README.md
@@ -51,7 +51,17 @@ Install-Module ImportExcel -scope CurrentUser
|
||||
```PowerShell
|
||||
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.
|
||||
- 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.
|
||||
|
||||
16
ToDo.md
16
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] Support "make worksheet active"
|
||||
- [X] Add checks for valid worksheet names
|
||||
- [x] Allow Exclude property to take wildcards
|
||||
- [X] Add -PivotTableSource parameter to Add-ExcelChart.
|
||||
- [X] Refactor Add-PivotTable to use Add-ExcelChart rather duplicating code. Add support for -ExcelChartDefinition support for all chart params ??
|
||||
- [X] Add -Passthru to Add-ExcelChart and Add-PivotTable
|
||||
- [X] Add support for PivotTable number format, data field name and possibly sort. -
|
||||
- [ ] 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
|
||||
- [ ] 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 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).
|
||||
- [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
|
||||
Reference in New Issue
Block a user