mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Better support of reverse in add-conditional formatting. Tidied Exampes
This commit is contained in:
@@ -68,6 +68,8 @@
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "NamedRuleAddress", Position = 3)]
|
||||
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
|
||||
#Text colour for matching objects
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[Parameter(ParameterSetName = "NamedRuleAddress")]
|
||||
[Alias("ForeGroundColour")]
|
||||
[System.Drawing.Color]$ForeGroundColor,
|
||||
#colour for databar type charts
|
||||
@@ -87,7 +89,9 @@
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSet")]
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "FiveIconSetAddress")]
|
||||
[OfficeOpenXml.ConditionalFormatting.eExcelconditionalFormatting5IconsSetType]$FiveIconsSet,
|
||||
#Use the icon set in reverse order
|
||||
#Use the icon set in reverse order, or reverse the orders of Two- & Three-Color Scales
|
||||
[Parameter(ParameterSetName = "NamedRule")]
|
||||
[Parameter(ParameterSetName = "NamedRuleAddress")]
|
||||
[Parameter(ParameterSetName = "ThreeIconSet")]
|
||||
[Parameter(ParameterSetName = "ThreeIconSetAddress")]
|
||||
[Parameter(ParameterSetName = "FourIconSet")]
|
||||
@@ -155,13 +159,18 @@
|
||||
}
|
||||
if ($Range -match "!") {$Range = $Range -replace '^.*!',''}
|
||||
|
||||
#region Create a rule of the right type
|
||||
#region create a rule of the right type
|
||||
if ($RuleType -match 'IconSet$') {Write-warning -Message "You cannot configure a IconSet rule in this way; please use -$RuleType <SetName>." ; return}
|
||||
if ($PSBoundParameters.ContainsKey("ThreeIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddThreeIconSet($Range , $ThreeIconsSet)}
|
||||
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFourIconSet( $Range , $FourIconsSet) }
|
||||
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFiveIconSet( $Range , $FiveIconsSet) }
|
||||
elseif ($PSBoundParameters.ContainsKey("DataBarColor" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddDatabar( $Range , $DataBarColor) }
|
||||
else {$rule = ($WorkSheet.ConditionalFormatting)."Add$RuleType"($Range)}
|
||||
if ($PSBoundParameters.ContainsKey("Reverse" ) ) {$rule.reverse = [boolean]$Reverse}
|
||||
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFourIconSet( $Range , $FourIconsSet )}
|
||||
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFiveIconSet( $Range , $FiveIconsSet )}
|
||||
elseif ($PSBoundParameters.ContainsKey("DataBarColor" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddDatabar( $Range , $DataBarColor )}
|
||||
else {$rule = ($WorkSheet.ConditionalFormatting)."Add$RuleType"($Range ) }
|
||||
if ($Reverse) {
|
||||
if ($rule.type -match 'IconSet$' ) {$rule.reverse = $true}
|
||||
elseif ($rule.type -match 'ColorScale$') {$temp =$rule.LowValue.Color ; $rule.LowValue.Color = $rule.HighValue.Color; $rule.HighValue.Color = $temp}
|
||||
else {Write-Warning -Message "-Reverse was ignored because $ruletype does not support it."}
|
||||
}
|
||||
#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.
|
||||
@@ -190,15 +199,15 @@
|
||||
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
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue" ) -and
|
||||
$RuleType -match "Top|Botom" ) {$rule.Rank = $ConditionValue }
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue" ) -and
|
||||
$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 '^=','') }
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue" ) -and
|
||||
$RuleType -match "Text|With" ) {$rule.Text = ($ConditionValue -replace '^=','') }
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue") -and
|
||||
if ($PSBoundParameters.ContainsKey("ConditionValue" ) -and
|
||||
$PSBoundParameters.ContainsKey("ConditionValue2") -and
|
||||
$RuleType -match "Between" ) {
|
||||
$rule.Formula = ($ConditionValue -replace '^=','');
|
||||
@@ -208,12 +217,12 @@
|
||||
if ($PSBoundParameters.ContainsKey("Priority") ) {$rule.Priority = $Priority }
|
||||
#endregion
|
||||
#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 }
|
||||
elseif ($PSBoundParameters.ContainsKey("Underline" ) ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::None }
|
||||
if ($PSBoundParameters.ContainsKey("Bold" ) ) {$rule.Style.Font.Bold = [boolean]$Bold }
|
||||
if ($PSBoundParameters.ContainsKey("Italic" ) ) {$rule.Style.Font.Italic = [boolean]$Italic }
|
||||
if ($PSBoundParameters.ContainsKey("StrikeThru") ) {$rule.Style.Font.Strike = [boolean]$StrikeThru }
|
||||
elseif ($PSBoundParameters.ContainsKey("Underline" ) ) {$rule.Style.Font.Underline = [OfficeOpenXml.Style.ExcelUnderLineType]::None }
|
||||
if ($PSBoundParameters.ContainsKey("Bold" ) ) {$rule.Style.Font.Bold = [boolean]$Bold }
|
||||
if ($PSBoundParameters.ContainsKey("Italic" ) ) {$rule.Style.Font.Italic = [boolean]$Italic }
|
||||
if ($PSBoundParameters.ContainsKey("StrikeThru" ) ) {$rule.Style.Font.Strike = [boolean]$StrikeThru }
|
||||
if ($PSBoundParameters.ContainsKey("ForeGroundColor" ) ) {$rule.Style.Font.Color.color = $ForeGroundColor }
|
||||
if ($PSBoundParameters.ContainsKey("BackgroundColor" ) ) {$rule.Style.Fill.BackgroundColor.color = $BackgroundColor }
|
||||
if ($PSBoundParameters.ContainsKey("BackgroundPattern") ) {$rule.Style.Fill.PatternType = $BackgroundPattern }
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
cls
|
||||
|
||||
ipmo ..\..\ImportExcel.psd1 -Force
|
||||
try {ipmo ..\..\ImportExcel.psd1 -Force} catch {}
|
||||
|
||||
$data = $(
|
||||
New-PSItem 100 (echo test testx)
|
||||
@@ -10,8 +8,8 @@ $data = $(
|
||||
New-PSItem 500
|
||||
)
|
||||
|
||||
$file1 = "tryComparison1.xlsx"
|
||||
$file2 = "tryComparison2.xlsx"
|
||||
$file1 = "$env:Temp\tryComparison1.xlsx"
|
||||
$file2 = "$env:Temp\tryComparison2.xlsx"
|
||||
|
||||
rm $file1 -ErrorAction Ignore
|
||||
rm $file2 -ErrorAction Ignore
|
||||
@@ -22,6 +20,6 @@ $data | Export-Excel $file1 -Show -ConditionalText $(
|
||||
)
|
||||
|
||||
$data | Export-Excel $file2 -Show -ConditionalText $(
|
||||
New-ConditionalText -ConditionalType GreaterThanOrEqual 275
|
||||
New-ConditionalText -ConditionalType GreaterThanOrEqual 275
|
||||
New-ConditionalText -ConditionalType LessThanOrEqual 250 -BackgroundColor cyan
|
||||
)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -40,4 +40,4 @@ $ptdef = New-PivotTableDefinition -PivotTableName "Summary" -PivotRows "Store" -
|
||||
#Put in a title and freeze to top of the sheet including title and colmun headings
|
||||
#Add the Pivot table.
|
||||
#Show the result
|
||||
Join-Worksheet -Path $path -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "Summary" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -PivotTableDefinition $ptdef -show
|
||||
Join-Worksheet -Path $path -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "Combined" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -PivotTableDefinition $ptdef -show
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,7 +3,7 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
|
||||
#. ..\New-PSItem.ps1
|
||||
|
||||
Remove-Item *.xlsx
|
||||
Remove-Item "$env:temp\functions.xlsx" -ErrorAction SilentlyContinue
|
||||
|
||||
$(
|
||||
New-PSItem 12001 Nails 37 3.99 =C2*D2 (echo ID Product Quantity Price Total)
|
||||
@@ -11,4 +11,4 @@ $(
|
||||
New-PSItem 12003 Saw 12 15.37 =C4*D4
|
||||
New-PSItem 12010 Drill 20 8 =C5*D5
|
||||
New-PSItem 12011 Crowbar 7 23.48 =C6*D6
|
||||
) | Export-Excel functions.xlsx -AutoSize -Show
|
||||
) | Export-Excel "$env:temp\functions.xlsx"-AutoSize -Show
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
|
||||
Remove-Item *.xlsx
|
||||
Remove-Item "$env:temp\functions.xlsx" -ErrorAction SilentlyContinue
|
||||
|
||||
$(
|
||||
New-PSItem =2%/12 60 500000 "=pmt(rate,nper,pv)" (echo rate nper pv pmt)
|
||||
@@ -9,4 +9,4 @@ $(
|
||||
New-PSItem =5%/12 60 500000 "=pmt(rate,nper,pv)"
|
||||
New-PSItem =6%/12 60 500000 "=pmt(rate,nper,pv)"
|
||||
New-PSItem =7%/12 60 500000 "=pmt(rate,nper,pv)"
|
||||
) | Export-Excel functions.xlsx -AutoNameRange -AutoSize -Show
|
||||
) | Export-Excel "$env:temp\functions.xlsx" -AutoNameRange -AutoSize -Show
|
||||
@@ -1,10 +1,10 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
|
||||
Remove-Item *.xlsx
|
||||
Remove-Item "$env:temp\hyperlink.xlsx" -ErrorAction SilentlyContinue
|
||||
|
||||
$(
|
||||
New-PSItem '=Hyperlink("http://dougfinke.com/blog","Doug Finke")' @("Link")
|
||||
New-PSItem '=Hyperlink("http://blogs.msdn.com/b/powershell/","PowerShell Blog")'
|
||||
New-PSItem '=Hyperlink("http://blogs.technet.com/b/heyscriptingguy/","Hey, Scripting Guy")'
|
||||
|
||||
) | Export-Excel hyperlink.xlsx -AutoSize -Show
|
||||
) | Export-Excel "$env:temp\hyperlink.xlsx" -AutoSize -Show
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,7 +25,7 @@ Function Get-ExcelTableName {
|
||||
$Stream.Close()
|
||||
$Stream.Dispose()
|
||||
$Excel.Dispose()
|
||||
$Excel = $null
|
||||
$Excel = $null
|
||||
}
|
||||
|
||||
Function Get-ExcelTable {
|
||||
@@ -66,7 +66,7 @@ Function Get-ExcelTable {
|
||||
$propertyNames = for($col=$startCol; $col -lt ($startCol+$colCount); $col+= 1) {
|
||||
$Worksheet.Cells[$startRow, $col].value
|
||||
}
|
||||
|
||||
|
||||
$startRow++
|
||||
for($row=$startRow; $row -lt ($startRow+$rowCount); $row += 1) {
|
||||
$nr=[ordered]@{}
|
||||
@@ -92,13 +92,11 @@ function ConvertFrom-ExcelColumnName {
|
||||
ForEach {
|
||||
$sum*=26
|
||||
$sum+=[char]$_.tostring().toupper()-[char]'A'+1
|
||||
}
|
||||
}
|
||||
$sum
|
||||
}
|
||||
|
||||
cls
|
||||
|
||||
ipmo .\ImportExcel.psd1 -Force
|
||||
|
||||
#Get-ExcelTableName .\testTable.xlsx | Get-ExcelTable .\testTable.xlsx
|
||||
#Get-ExcelTableName .\testTable.xlsx | Get-ExcelTable .\testTable.xlsx
|
||||
Get-ExcelTable .\testTable.xlsx Table3
|
||||
20
README.md
20
README.md
@@ -51,18 +51,16 @@ Install-Module ImportExcel -scope CurrentUser
|
||||
```PowerShell
|
||||
Install-Module ImportExcel
|
||||
```
|
||||
- Lots of help improvements.
|
||||
- Conditional formatting can now support named ranges, and booleans in the sheet as a condition. Also brought the two different kinds together inside export-excel
|
||||
- Improved handling of hyperlinks.
|
||||
- Moved logic for adding a named range out of Export-Excel and into new function named Add-ExcelName, and for adding a table into a function named Add-Excel table; this is to make it easier to do these things independently of Export-Excel but minimize duplication. Add-Table command can now toggle the options from table tools toolbar (show totals etc)
|
||||
- Fixed issues where formatting could be reset when using Export-Excel to manipulate an existing sheet without appending data; this applied to number formats and tables.
|
||||
- Lots of help improvements and some tidying up of examples
|
||||
- `Add-ConditionalFormatting`: Now wraps those strings in quotes when needed (for = <= >= string needs to be in double quotes). Parameter intellisense has been improved. There are new parameters: -StopIfTrue and -Priority and support for using the -Reverse parameter with Color-scale rules. Booleans in the sheet are now supported as the value for a condition. Also brought the two different kinds of condition together inside export-excel, and fixed a bug where named-ranges didn't work in some places. In `New-ConditionalText`, more types of conditional format are supported, and -ConditionalTextColor now has an argument completer
|
||||
- Improved handling of hyperlinks in `Export-Excel`.
|
||||
- `Export-Excel` has better checking of Table and PivotTable names (for uniqueness) and a new test in quick charts that there is suitable data for charting.
|
||||
- Moved logic for adding a named range out of Export-Excel and into a new function named `Add-ExcelName`, and logic for adding a table into a function named `Add-ExcelTable`; this is to make it easier to do these things independently of Export-Excel, but minimize duplication. The Add-ExcelTable command has extra parameters to toggle the options from table tools toolbar (show totals etc)
|
||||
- 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 now 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), added StopIfTrue and Priority Parameters
|
||||
- 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 .
|
||||
- Fixed issues where formatting could be reset when using Export-Excel to manipulate an existing sheet without appending data; this applied to number-formats and tables.
|
||||
- `Add-PivotTable` has some new parameters -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. Chart creation has been moved out to Add-ExcelChart, and -PivotChartDefinition allows a defintion created with New-ExcelChartDefinition to be used with a PivotTable. 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` .
|
||||
- `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. And in `New-ExcelChartDefinition` Legend parameters (for size, bold & position ) are now supported
|
||||
|
||||
|
||||
# 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.
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
$Excel = New-Object -TypeName OfficeOpenXml.ExcelPackage $Path
|
||||
|
||||
$workSheet = $Excel.Workbook.Worksheets[$WorkSheetName]
|
||||
|
||||
|
||||
if($workSheet) {
|
||||
if($Excel.Workbook.Worksheets.Count -gt 1) {
|
||||
$Excel.Workbook.Worksheets.Delete($workSheet)
|
||||
@@ -22,14 +22,13 @@
|
||||
}
|
||||
|
||||
$Excel.Save()
|
||||
$Excel.Dispose()
|
||||
$Excel.Dispose()
|
||||
}
|
||||
|
||||
cls
|
||||
|
||||
ipmo .\ImportExcel.psd1 -Force
|
||||
Import-Module .\ImportExcel.psd1 -Force
|
||||
|
||||
$names = Get-ExcelSheetInfo C:\Temp\testDelete.xlsx
|
||||
$names = Get-ExcelSheetInfo C:\Temp\testDelete.xlsx
|
||||
$names | % { Remove-WorkSheet C:\Temp\testDelete.xlsx $_.Name}
|
||||
|
||||
##Remove-WorkSheet C:\Temp\testDelete.xlsx sheet6
|
||||
@@ -1,4 +1,4 @@
|
||||
Race,Date,FinishPosition,Driver,GridPostion,Team,Points
|
||||
Race,Date,FinishPosition,Driver,GridPosition,Team,Points
|
||||
Australian,25/03/2018,1,Sebastian Vettel,3,Ferrari,25
|
||||
Australian,25/03/2018,2,Lewis Hamilton,1,Mercedes,18
|
||||
Australian,25/03/2018,3,Kimi Räikkönen,2,Ferrari,15
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent
|
||||
$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.csv"
|
||||
|
||||
|
||||
Describe "Creating small named ranges with hyperlinks" {
|
||||
BeforeAll {
|
||||
$path = "$env:TEMP\Results.xlsx"
|
||||
@@ -18,27 +18,29 @@ Describe "Creating small named ranges with hyperlinks" {
|
||||
$worksheet = $excel.Workbook.Worksheets[1]
|
||||
$columns = $worksheet.Dimension.Columns
|
||||
|
||||
1..$columns | foreach {Add-ExcelName -Range $worksheet.cells[$topRow,$_,$lastDataRow,$_]}
|
||||
1..$columns | foreach {Add-ExcelName -Range $worksheet.cells[$topRow,$_,$lastDataRow,$_]} #Test Add-Excel Name on its own (outside Export-Excel)
|
||||
|
||||
$scwarnVar = $null
|
||||
Set-Column -Worksheet $worksheet -StartRow $topRow -Heading "PlacesGained/Lost" -Value "=GridPostion-FinishPosition" -AutoNameRange -WarningVariable scWarnVar -WarningAction SilentlyContinue
|
||||
Set-Column -Worksheet $worksheet -StartRow $topRow -Heading "PlacesGained/Lost" `
|
||||
-Value "=GridPosition-FinishPosition" -AutoNameRange -WarningVariable scWarnVar -WarningAction SilentlyContinue #Test as many set column options as possible.
|
||||
$columns ++
|
||||
|
||||
#create a table which covers all the data. And define a pivot table which uses the same address range.
|
||||
$table = Add-ExcelTable -PassThru -Range $worksheet.cells[$topRow,1,$lastDataRow,$columns] -TableName "AllResults" -TableStyle Light7 -ShowHeader -ShowFilter -ShowColumnStripes -ShowRowStripes:$false -ShowFirstColumn:$false -ShowLastColumn:$false -ShowTotal:$false
|
||||
$table = Add-ExcelTable -PassThru -Range $worksheet.cells[$topRow,1,$lastDataRow,$columns] -TableName "AllResults" -TableStyle Light4 `
|
||||
-ShowHeader -ShowFilter -ShowColumnStripes -ShowRowStripes:$false -ShowFirstColumn:$false -ShowLastColumn:$false -ShowTotal:$false #Test Add-ExcelTable outside export-Excel with as many options as possible.
|
||||
$pt = New-PivotTableDefinition -PivotTableName Analysis -SourceWorkSheet $worksheet -SourceRange $table.address.address -PivotRows Driver -PivotData @{Points="SUM"} -PivotTotals None
|
||||
|
||||
$cf = Add-ConditionalFormatting -Address $worksheet.cells[$topRow,$columns,$lastDataRow,$columns] -ThreeIconsSet Arrows -Passthru
|
||||
$cf = Add-ConditionalFormatting -Address $worksheet.cells[$topRow,$columns,$lastDataRow,$columns] -ThreeIconsSet Arrows -Passthru #Test using cells[r1,c1,r2,c2]
|
||||
$cf.Icon2.Type = $cf.Icon3.Type = "Num"
|
||||
$cf.Icon2.Value = 0
|
||||
$cf.Icon3.Value = 1
|
||||
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue
|
||||
|
||||
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue #Test Priority and stopIfTrue and using range name
|
||||
Add-ConditionalFormatting -Address $worksheet.Cells["GridPosition"] -RuleType ThreeColorScale -Reverse #Test Reverse
|
||||
$ct = New-ConditionalText -Text "Ferrari"
|
||||
$ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalTextColor Red -BackgroundColor White
|
||||
$ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalText Red -Background White #Test new-conditionalText in shortest and longest forms.
|
||||
#Create links for each group name (race) and Export them so they start at Cell A1; create a pivot table with definition just created, save the file and open in Excel
|
||||
$results | foreach {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} |
|
||||
Export-Excel -ExcelPackage $excel -AutoSize -PivotTableDefinition $pt -Calculate -Conditionaltext $ct,$ct2
|
||||
$results | foreach {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} | #Test Exporting Hyperlinks with display property.
|
||||
Export-Excel -ExcelPackage $excel -AutoSize -PivotTableDefinition $pt -Calculate -ConditionalFormat $ct,$ct2 #Test conditional text rules in conditional format (orignally icon sets only )
|
||||
|
||||
$excel = Open-ExcelPackage $path
|
||||
$sheet = $excel.Workbook.Worksheets[1]
|
||||
@@ -47,9 +49,9 @@ Describe "Creating small named ranges with hyperlinks" {
|
||||
}
|
||||
Context "Creating hyperlinks" {
|
||||
it "Put the data into the sheet and created the expected named ranges " {
|
||||
$sheet.dimension.rows | should be $expectedRows
|
||||
$sheet.dimension.columns | should be $columns
|
||||
$sheet.names.count | should be ($columns + $results.Count)
|
||||
$sheet.Dimension.Rows | should be $expectedRows
|
||||
$sheet.Dimension.Columns | should be $columns
|
||||
$sheet.Names.Count | should be ($columns + $results.Count)
|
||||
$sheet.Names[$results[0].Name] | should not benullorEmpty
|
||||
$sheet.Names[$results[-1].Name] | should not benullorEmpty
|
||||
}
|
||||
@@ -62,14 +64,14 @@ Describe "Creating small named ranges with hyperlinks" {
|
||||
It "Populated the cells with the right heading and formulas " {
|
||||
$sheet.Cells[( $results.Count),$columns] | Should benullorEmpty
|
||||
$sheet.Cells[(1+$results.Count),$columns].Value | Should be "PlacesGained/Lost"
|
||||
$sheet.Cells[(2+$results.Count),$columns].Formula | should be "GridPostion-FinishPosition"
|
||||
$sheet.Cells[(2+$results.Count),$columns].Formula | should be "GridPosition-FinishPosition"
|
||||
$sheet.Names["PlacesGained_Lost"] | should not benullorEmpty
|
||||
}
|
||||
It "Performed the calculation " {
|
||||
$placesMade = $Sheet.Cells[(2+$results.Count),5].value - $Sheet.Cells[(2+$results.Count),3].value
|
||||
$sheet.Cells[(2+$results.Count),$columns].value | Should be $placesmade
|
||||
}
|
||||
It "Applied ConditionalFormatting, including stopifTrue and Priority " {
|
||||
It "Applied ConditionalFormatting, including StopIfTrue, Priority and Reverse " {
|
||||
$sheet.ConditionalFormatting[0].Address.Start.Column | should be $columns
|
||||
$sheet.ConditionalFormatting[0].Address.End.Column | should be $columns
|
||||
$sheet.ConditionalFormatting[0].Address.End.Row | should be $expectedRows
|
||||
@@ -78,16 +80,20 @@ Describe "Creating small named ranges with hyperlinks" {
|
||||
$sheet.ConditionalFormatting[0].Icon3.Value | Should be 1
|
||||
$sheet.ConditionalFormatting[1].Priority | Should be 1
|
||||
$sheet.ConditionalFormatting[1].StopIfTrue | Should be $true
|
||||
$sheet.ConditionalFormatting[3].LowValue.Color.R | Should begreaterThan 180
|
||||
$sheet.ConditionalFormatting[3].LowValue.Color.G | Should beLessThan 128
|
||||
$sheet.ConditionalFormatting[3].HighValue.Color.R | Should beLessThan 128
|
||||
$sheet.ConditionalFormatting[3].HighValue.Color.G | Should begreaterThan 180
|
||||
}
|
||||
}
|
||||
Context "Adding adding a table" {
|
||||
Context "Adding a table" {
|
||||
it "Created a table " {
|
||||
$sheet.tables[0] | Should not beNullOrEmpty
|
||||
$sheet.tables[0].Address.Start.Column | should be 1
|
||||
$sheet.tables[0].Address.End.Column | should be $columns
|
||||
$sheet.tables[0].Address.Start.row | should be ($results.Count + 1)
|
||||
$sheet.Tables[0].Address.End.Row | should be $expectedRows
|
||||
$sheet.Tables[0].StyleName | should be "TableStyleLight7"
|
||||
$sheet.Tables[0].StyleName | should be "TableStyleLight4"
|
||||
$sheet.Tables[0].ShowColumnStripes | should be $true
|
||||
$sheet.Tables[0].ShowRowStripes | should not be $true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user