Epplus is not setting chart axis position properly, so disabled for now

This commit is contained in:
jhoneill
2018-08-14 15:40:52 +01:00
parent f768634214
commit c49b7b6db0
2 changed files with 49 additions and 30 deletions

View File

@@ -635,10 +635,8 @@
#Otherwise the default will be unbolded. #Otherwise the default will be unbolded.
$ws.Cells[$Row, $StartColumn].Style.Font.Bold = $True $ws.Cells[$Row, $StartColumn].Style.Font.Bold = $True
} }
$ws.Cells[$Row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern
if ($TitleBackgroundColor ) { if ($TitleBackgroundColor ) {
$ws.Cells[$Row, $StartColumn].Style.Fill.PatternType = $TitleFillPattern
$ws.Cells[$Row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor) $ws.Cells[$Row, $StartColumn].Style.Fill.BackgroundColor.SetColor($TitleBackgroundColor)
} }
$Row ++ ; $startRow ++ $Row ++ ; $startRow ++
@@ -1413,7 +1411,8 @@ function Add-ExcelChart {
if ($XAxisTitleBold) {$chart.XAxis.Title.Font.Bold = $true} if ($XAxisTitleBold) {$chart.XAxis.Title.Font.Bold = $true}
if ($XAxisTitleSize) {$chart.XAxis.Title.Font.Size = $XAxisTitleSize} if ($XAxisTitleSize) {$chart.XAxis.Title.Font.Size = $XAxisTitleSize}
} }
if ($XAxisPosition) {$chart.ChartXml.chartSpace.chart.plotArea.catAx.axPos.val = $XAxisPosition.ToString().substring(0,1)} if ($XAxisPosition) {Write-Warning "X Axis position is not being set propertly at the moment, parameter ignored" }
#$chart.ChartXml.chartSpace.chart.plotArea.catAx.axPos.val = $XAxisPosition.ToString().substring(0,1)}
if ($XMajorUnit) {$chart.XAxis.MajorUnit = $XMajorUnit} if ($XMajorUnit) {$chart.XAxis.MajorUnit = $XMajorUnit}
if ($XMinorUnit) {$chart.XAxis.MinorUnit = $XMinorUnit} if ($XMinorUnit) {$chart.XAxis.MinorUnit = $XMinorUnit}
if ($null -ne $XMinValue) {$chart.XAxis.MinValue = $XMinValue} if ($null -ne $XMinValue) {$chart.XAxis.MinValue = $XMinValue}
@@ -1425,7 +1424,8 @@ function Add-ExcelChart {
if ($YAxisTitleBold) {$chart.YAxis.Title.Font.Bold = $true} if ($YAxisTitleBold) {$chart.YAxis.Title.Font.Bold = $true}
if ($YAxisTitleSize) {$chart.YAxis.Title.Font.Size = $YAxisTitleSize} if ($YAxisTitleSize) {$chart.YAxis.Title.Font.Size = $YAxisTitleSize}
} }
if ($YAxisPosition) {$chart.ChartXml.chartSpace.chart.plotArea.valAx.axPos.val= $YAxisPosition.ToString().substring(0,1)} if ($YAxisPosition) {Write-Warning "Y Axis position is not being set propertly at the moment, parameter ignored" }
#$chart.ChartXml.chartSpace.chart.plotArea.valAx.axPos.val= $YAxisPosition.ToString().substring(0,1)}
if ($YMajorUnit) {$chart.YAxis.MajorUnit = $YMajorUnit} if ($YMajorUnit) {$chart.YAxis.MajorUnit = $YMajorUnit}
if ($YMinorUnit) {$chart.YAxis.MinorUnit = $YMinorUnit} if ($YMinorUnit) {$chart.YAxis.MinorUnit = $YMinorUnit}
if ($null -ne $YMinValue){$chart.YAxis.MinValue = $YMinValue} if ($null -ne $YMinValue){$chart.YAxis.MinValue = $YMinValue}

View File

@@ -8,7 +8,7 @@ Describe ExportExcel {
Context "#Example 1 # Creates and opens a file with the right number of rows and columns" { Context "#Example 1 # Creates and opens a file with the right number of rows and columns" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
#Export maximum of 100 processes for speed; export all properties. #Test with a maximum of 100 processes for speed; export all properties, then export smaller subsets.
$processes = Get-Process | select-object -first 100 $processes = Get-Process | select-object -first 100
$propertyNames = $Processes[0].psobject.properties.name $propertyNames = $Processes[0].psobject.properties.name
$rowcount = $Processes.Count $rowcount = $Processes.Count
@@ -68,7 +68,7 @@ Describe ExportExcel {
$processes = Get-Process | Select-Object -First 100 $processes = Get-Process | Select-Object -First 100
$propertyNames = $Processes[0].psobject.properties.where( {$_.MemberType -eq 'Property'}).name $propertyNames = $Processes[0].psobject.properties.where( {$_.MemberType -eq 'Property'}).name
$rowcount = $Processes.Count $rowcount = $Processes.Count
#Test -NoAliasOrScriptPropeties option and Creating a range with a name which needs illegal chars removing - check this sends back a warning #Test -NoAliasOrScriptPropeties option and creating a range with a name which needs illegal chars removing - check this sends back a warning
$warnVar = $null $warnVar = $null
$Processes | Export-Excel $path -NoAliasOrScriptPropeties -RangeName "No Spaces" -WarningVariable warnvar -WarningAction SilentlyContinue $Processes | Export-Excel $path -NoAliasOrScriptPropeties -RangeName "No Spaces" -WarningVariable warnvar -WarningAction SilentlyContinue
@@ -85,12 +85,12 @@ Describe ExportExcel {
$ws.names["No_spaces"].End.Row | Should be ($rowcount + 1 ) # +1 for the header. $ws.names["No_spaces"].End.Row | Should be ($rowcount + 1 ) # +1 for the header.
$warnVar.Count | Should be 1 $warnVar.Count | Should be 1
} }
#This time use clearsheet instead of deleting the file #This time use clearsheet instead of deleting the file test -Exclude properties, including wildcards.
$Processes | Export-Excel $path -ClearSheet -NoAliasOrScriptPropeties -ExcludeProperty SafeHandle, threads, modules, MainModule, StartInfo, MachineName, MainWindow*, M*workingSet $Processes | Export-Excel $path -ClearSheet -NoAliasOrScriptPropeties -ExcludeProperty SafeHandle, threads, modules, MainModule, StartInfo, MachineName, MainWindow*, M*workingSet
$Excel = Open-ExcelPackage -Path $path $Excel = Open-ExcelPackage -Path $path
$ws = $Excel.Workbook.Worksheets[1] $ws = $Excel.Workbook.Worksheets[1]
it "Created a new file with a further 5 properties excluded and cleared the old sheet " { it "Created a new file with further properties excluded and cleared the old sheet " {
$ws.Name | Should be "sheet1" $ws.Name | Should be "sheet1"
$ws.Dimension.Columns | Should be ($propertyNames.Count - 10) $ws.Dimension.Columns | Should be ($propertyNames.Count - 10)
$ws.Dimension.Rows | Should be ($rowcount + 1) # +1 for the header $ws.Dimension.Rows | Should be ($rowcount + 1) # +1 for the header
@@ -98,6 +98,7 @@ Describe ExportExcel {
$propertyNames = $Processes[0].psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames $propertyNames = $Processes[0].psStandardmembers.DefaultDisplayPropertySet.ReferencedPropertyNames
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
#Test -DisplayPropertySet
$Processes | Export-Excel $path -DisplayPropertySet $Processes | Export-Excel $path -DisplayPropertySet
$Excel = Open-ExcelPackage -Path $path $Excel = Open-ExcelPackage -Path $path
@@ -148,7 +149,7 @@ Describe ExportExcel {
else {$OtherCurrencySymbol = "£"} else {$OtherCurrencySymbol = "£"}
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
$warnVar = $null $warnVar = $null
#Check various types and number formats, and confirm that a property which is an object gets converted to a string with no warnings. #Test correct export of different data types and number formats; test hyperlinks, test -NoNumberConversion test object is converted to a string with no warnings, test calcuation of formula
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
[PSCustOmobject][Ordered]@{ [PSCustOmobject][Ordered]@{
Date = Get-Date Date = Get-Date
@@ -256,6 +257,7 @@ Describe ExportExcel {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
#Test -NoHeader & -NoNumberConversion
[PSCustOmobject][Ordered]@{ [PSCustOmobject][Ordered]@{
Date = Get-Date Date = Get-Date
Formula1 = '=SUM(F1:G1)' Formula1 = '=SUM(F1:G1)'
@@ -311,6 +313,7 @@ Describe ExportExcel {
} }
Context "#Example 5 # Adding a single conditional format " { Context "#Example 5 # Adding a single conditional format " {
#Test New-ConditionalText builds correctly
$ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink $ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink
it "Created a Conditional format description " { it "Created a Conditional format description " {
$ct.BackgroundColor -is [System.Drawing.Color] | Should be $true $ct.BackgroundColor -is [System.Drawing.Color] | Should be $true
@@ -321,13 +324,14 @@ Describe ExportExcel {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
#Test -ConditionalText with a single conditional spec.
Write-Output 489 668 299 777 860 151 119 497 234 788 | Export-Excel -Path $path -ConditionalText $ct Write-Output 489 668 299 777 860 151 119 497 234 788 | Export-Excel -Path $path -ConditionalText $ct
it "Created a new file " { it "Created a new file " {
Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true
} }
#ToDo need to test applying conitional formatting to a pre-existing worksheet #ToDo need to test applying conitional formatting to a pre-existing worksheet and removing = from formula
$Excel = Open-ExcelPackage -Path $path $Excel = Open-ExcelPackage -Path $path
$ws = $Excel.Workbook.Worksheets[1] $ws = $Excel.Workbook.Worksheets[1]
@@ -342,13 +346,11 @@ Describe ExportExcel {
$cf.Type.ToString() | Should be $ct.ConditionalType $cf.Type.ToString() | Should be $ct.ConditionalType
#$cf.Style.Fill.BackgroundColor | Should be $ct.BackgroundColor #$cf.Style.Fill.BackgroundColor | Should be $ct.BackgroundColor
# $cf.Style.Font.Color | Should be $ct.ConditionalTextColor - have to compare r.g.b # $cf.Style.Font.Color | Should be $ct.ConditionalTextColor - have to compare r.g.b
} }
} }
Context "#Example 6 # Adding multiple conditional formats using short form syntax. " { Context "#Example 6 # Adding multiple conditional formats using short form syntax. " {
#this is a test of adding more than one conditional block and using the minimal syntax for new-ConditionalText = #Test adding mutliple conditional blocks and using the minimal syntax for new-ConditionalText
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue Remove-item -Path $path -ErrorAction SilentlyContinue
@@ -396,6 +398,7 @@ Describe ExportExcel {
} }
$Array = $Obj1, $Obj2, $Obj3 $Array = $Obj1, $Obj2, $Obj3
#test Update-FirstObjectProperties
$newarray = $Array | Update-FirstObjectProperties $newarray = $Array | Update-FirstObjectProperties
it "Outputs as many objects as it input " { it "Outputs as many objects as it input " {
$newarray.Count | Should be $Array.Count $newarray.Count | Should be $Array.Count
@@ -411,9 +414,9 @@ Describe ExportExcel {
Context "#Examples 8 & 9 # Adding Pivot tables and charts from parameters" { Context "#Examples 8 & 9 # Adding Pivot tables and charts from parameters" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
#This time we are not deleting the XLSX file so this Should create a new, named, sheet. #Test -passthru and -worksheetName creating a new, named, sheet in an existing file.
$Excel = Get-Process | Select-Object -first 20 -Property Name, cpu, pm, handles, company | Export-Excel $path -WorkSheetname Processes -PassThru $Excel = Get-Process | Select-Object -first 20 -Property Name, cpu, pm, handles, company | Export-Excel $path -WorkSheetname Processes -PassThru
#Testing -passthru and adding the Pivot as a second step. Want to save and re-open it ... #Testing -Excel Pacakage and adding a Pivot-table as a second step. Want to save and re-open it ...
Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -NoTotalsInPivot Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -NoTotalsInPivot
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -435,7 +438,7 @@ Describe ExportExcel {
$pt.DataFields[0].Field.Name | Should be "PM" $pt.DataFields[0].Field.Name | Should be "PM"
$PTws.Drawings.Count | Should be 0 $PTws.Drawings.Count | Should be 0
} }
#using the already open sheet add the pivot chart #test adding pivot chart using the already open sheet
$warnvar = $null $warnvar = $null
Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -IncludePivotChart -ChartType PieExploded3D -ShowCategory -NoLegend -WarningAction SilentlyContinue -WarningVariable warnvar Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -IncludePivotChart -ChartType PieExploded3D -ShowCategory -NoLegend -WarningAction SilentlyContinue -WarningVariable warnvar
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -448,6 +451,7 @@ Describe ExportExcel {
it "Generated a message on re-processing the Pivot table " { it "Generated a message on re-processing the Pivot table " {
$warnVar | Should not beNullOrEmpty $warnVar | Should not beNullOrEmpty
} }
#Test appending data extends pivot chart (with a warning) .
$warnVar = $null $warnVar = $null
Get-Process | Select-Object -Last 20 -Property Name, cpu, pm, handles, company | Export-Excel $path -WorkSheetname Processes -Append -IncludePivotTable -PivotRows Company -PivotData PM -IncludePivotChart -ChartType PieExploded3D -WarningAction SilentlyContinue -WarningVariable warnvar Get-Process | Select-Object -Last 20 -Property Name, cpu, pm, handles, company | Export-Excel $path -WorkSheetname Processes -Append -IncludePivotTable -PivotRows Company -PivotData PM -IncludePivotChart -ChartType PieExploded3D -WarningAction SilentlyContinue -WarningVariable warnvar
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -465,7 +469,7 @@ Describe ExportExcel {
Context " # Add-Worksheet inserted sheets, moved them correctly, and copied a sheet" { Context " # Add-Worksheet inserted sheets, moved them correctly, and copied a sheet" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
#Test the -CopySource and -Movexxxx parameters for Add-WorkSheet
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
#At this point Sheets Should be in the order Sheet1, Processes, ProcessesPivotTable #At this point Sheets Should be in the order Sheet1, Processes, ProcessesPivotTable
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "Processes" -MoveToEnd # order now Sheet1, ProcessesPivotTable, Processes $null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "Processes" -MoveToEnd # order now Sheet1, ProcessesPivotTable, Processes
@@ -501,7 +505,7 @@ Describe ExportExcel {
remove-item -Path $path -ErrorAction SilentlyContinue remove-item -Path $path -ErrorAction SilentlyContinue
#Catch warning #Catch warning
$warnVar = $null $warnVar = $null
#Test Append with no existing sheet. Test adding a named pivot table from command line parametesr and extending ranges when they're not specified explictly #Test -Append with no existing sheet. Test adding a named pivot table from command line parameters and extending ranges when they're not specified explictly
Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -StartRow 3 -StartColumn 3 -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -Append -PivotFilter Name -NoTotalsInPivot -RangeName procs -AutoFilter -AutoNameRange Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -StartRow 3 -StartColumn 3 -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -Append -PivotFilter Name -NoTotalsInPivot -RangeName procs -AutoFilter -AutoNameRange
Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -StartRow 3 -StartColumn 3 -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -Append -WarningAction SilentlyContinue -WarningVariable warnvar Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -StartRow 3 -StartColumn 3 -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -Append -WarningAction SilentlyContinue -WarningVariable warnvar
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -547,6 +551,7 @@ Describe ExportExcel {
Context " # Create and append explicit and auto table and range extension" { Context " # Create and append explicit and auto table and range extension" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
#Test -Append automatically extends a table, even when it is not specified in the append command
Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -Path $path -TableName ProcTab -AutoNameRange -WorkSheetname NoOffset -ClearSheet Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -Path $path -TableName ProcTab -AutoNameRange -WorkSheetname NoOffset -ClearSheet
Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -Path $path -AutoNameRange -WorkSheetname NoOffset -Append Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -Path $path -AutoNameRange -WorkSheetname NoOffset -Append
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -558,6 +563,7 @@ Describe ExportExcel {
$dataWs.Names["CPU"].Columns | should be 1 $dataWs.Names["CPU"].Columns | should be 1
} }
#Test extneding autofilter and range when explicitly specified in the append
$excel = Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -ExcelPackage $excel -RangeName procs -AutoFilter -WorkSheetname NoOffset -ClearSheet -PassThru $excel = Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company | Export-Excel -ExcelPackage $excel -RangeName procs -AutoFilter -WorkSheetname NoOffset -ClearSheet -PassThru
Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -ExcelPackage $excel -RangeName procs -AutoFilter -WorkSheetname NoOffset -Append Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -ExcelPackage $excel -RangeName procs -AutoFilter -WorkSheetname NoOffset -Append
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -574,6 +580,7 @@ Describe ExportExcel {
Context "#Example 11 # Create and append with title, inc ranges and Pivot table" { Context "#Example 11 # Create and append with title, inc ranges and Pivot table" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
#Test New-PivotTableDefinition builds definition using -Pivotfilter and -PivotTotals options.
$ptDef = [ordered]@{} $ptDef = [ordered]@{}
$ptDef += New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet 'Sheet1' -PivotRows "Status" -PivotData @{'Status' = 'Count'} -PivotTotals Columns -PivotFilter "StartType" -IncludePivotChart -ChartType BarClustered3D -ChartTitle "Services by status" -ChartHeight 512 -ChartWidth 768 -ChartRow 10 -ChartColumn 0 -NoLegend -PivotColumns CanPauseAndContinue $ptDef += New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet 'Sheet1' -PivotRows "Status" -PivotData @{'Status' = 'Count'} -PivotTotals Columns -PivotFilter "StartType" -IncludePivotChart -ChartType BarClustered3D -ChartTitle "Services by status" -ChartHeight 512 -ChartWidth 768 -ChartRow 10 -ChartColumn 0 -NoLegend -PivotColumns CanPauseAndContinue
$ptDef += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet 'Sheet2' -PivotRows "Company" -PivotData @{'Company' = 'Count'} -PivotTotalS Rows -IncludePivotChart -ChartType PieExploded3D -ShowPercent -WarningAction SilentlyContinue $ptDef += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet 'Sheet2' -PivotRows "Company" -PivotData @{'Company' = 'Count'} -PivotTotalS Rows -IncludePivotChart -ChartType PieExploded3D -ShowPercent -WarningAction SilentlyContinue
@@ -590,6 +597,7 @@ Describe ExportExcel {
Remove-Item -Path $path Remove-Item -Path $path
#Catch warning #Catch warning
$warnvar = $null $warnvar = $null
#Test create two data pages; as part of adding the second give both their own pivot table, test -autosize switch
Get-Service | Select-Object -Property Status, Name, DisplayName, StartType, CanPauseAndContinue | Export-Excel -Path $path -AutoSize -TableName "All Services" -TableStyle Medium1 -WarningAction SilentlyContinue -WarningVariable warnvar Get-Service | Select-Object -Property Status, Name, DisplayName, StartType, CanPauseAndContinue | Export-Excel -Path $path -AutoSize -TableName "All Services" -TableStyle Medium1 -WarningAction SilentlyContinue -WarningVariable warnvar
Get-Process | Select-Object -Property Name, Company, Handles, CPU, VM | Export-Excel -Path $path -AutoSize -WorkSheetname 'sheet2' -TableName "Processes" -TableStyle Light1 -Title "Processes" -TitleFillPattern Solid -TitleBackgroundColor AliceBlue -TitleBold -TitleSize 22 -PivotTableDefinition $ptDef Get-Process | Select-Object -Property Name, Company, Handles, CPU, VM | Export-Excel -Path $path -AutoSize -WorkSheetname 'sheet2' -TableName "Processes" -TableStyle Light1 -Title "Processes" -TitleFillPattern Solid -TitleBackgroundColor AliceBlue -TitleBold -TitleSize 22 -PivotTableDefinition $ptDef
$Excel = Open-ExcelPackage $path $Excel = Open-ExcelPackage $path
@@ -655,6 +663,7 @@ Describe ExportExcel {
Context "#Example 13 # Formatting and another way to do a pivot. " { Context "#Example 13 # Formatting and another way to do a pivot. " {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-Item $path Remove-Item $path
#Test freezing top row/first column, adding formats and a pivot table - from Add-Pivot table not a specification variable - after the export
$excel = Get-Process | Select-Object -Property Name, Company, Handles, CPU, PM, NPM, WS | Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -FreezeTopRowFirstColumn -PassThru $excel = Get-Process | Select-Object -Property Name, Company, Handles, CPU, PM, NPM, WS | Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -FreezeTopRowFirstColumn -PassThru
$sheet = $excel.Workbook.Worksheets["Processes"] $sheet = $excel.Workbook.Worksheets["Processes"]
$sheet.Column(1) | Set-Format -Bold -AutoFit $sheet.Column(1) | Set-Format -Bold -AutoFit
@@ -721,7 +730,8 @@ Describe ExportExcel {
Context " # Chart from MultiSeries.ps1 in the Examples\charts Directory" { Context " # Chart from MultiSeries.ps1 in the Examples\charts Directory" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
Remove-Item -Path $path -ErrorAction SilentlyContinue Remove-Item -Path $path -ErrorAction SilentlyContinue
$data = invoke-sum (Get-Process) Company Handles, PM, VirtualMemorySize #Test Invoke-Sum
$data = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize
it "used Invoke-Sum to create a data set " { it "used Invoke-Sum to create a data set " {
$data | Should not beNullOrEmpty $data | Should not beNullOrEmpty
$data.count | Should beGreaterThan 1 $data.count | Should beGreaterThan 1
@@ -746,6 +756,7 @@ Describe ExportExcel {
$c.ShowCategory | Should not be $true $c.ShowCategory | Should not be $true
$c.ShowPercent | Should not be $true $c.ShowPercent | Should not be $true
} }
#Test creating a chart using -ExcelChartDefinition.
$data | Export-Excel $path -AutoSize -TableName Processes -ExcelChartDefinition $c $data | Export-Excel $path -AutoSize -TableName Processes -ExcelChartDefinition $c
$excel = Open-ExcelPackage -Path $path $excel = Open-ExcelPackage -Path $path
$drawings = $excel.Workbook.Worksheets[1].drawings $drawings = $excel.Workbook.Worksheets[1].drawings
@@ -764,12 +775,16 @@ Describe ExportExcel {
Context " # variation of plot.ps1 from Examples Directory using Add chart outside ExportExcel" { Context " # variation of plot.ps1 from Examples Directory using Add chart outside ExportExcel" {
$path = "$env:TEMP\Test.xlsx" $path = "$env:TEMP\Test.xlsx"
#Test inserting a fomual
$excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path $path -WorkSheetname SinX -ClearSheet -FreezeFirstColumn -PassThru $excel = 0..360 | ForEach-Object {[pscustomobject][ordered]@{x = $_; Sinx = "=Sin(Radians(x)) "}} | Export-Excel -AutoNameRange -Path $path -WorkSheetname SinX -ClearSheet -FreezeFirstColumn -PassThru
#Test-Add Excel Chart to existing data. Test add Conditional formatting with a formula
Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -ChartType line -XRange "X" -YRange "Sinx" -SeriesHeader "Sin(x)" -Title "Graph of Sine X" -TitleBold -TitleSize 14 ` Add-ExcelChart -Worksheet $excel.Workbook.Worksheets["Sinx"] -ChartType line -XRange "X" -YRange "Sinx" -SeriesHeader "Sin(x)" -Title "Graph of Sine X" -TitleBold -TitleSize 14 `
-Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000"` -XAxisPosition Bottom ` -Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" `
-YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 -YAxisPosition Left ` -YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 `
-LegendSize 8 -legendBold -LegendPostion Bottom -LegendSize 8 -legendBold -LegendPostion Bottom
$d = $excel.Workbook.Worksheets["Sinx"].Drawings[0] Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets["Sinx"] -Range "B2:B362" -RuleType LessThan -ConditionValue "=B1" -ForeGroundColor Red
$ws = $Excel.Workbook.Worksheets["Sinx"]
$d = $ws.Drawings[0]
It "Controled the axes and title and legend of the chart " { It "Controled the axes and title and legend of the chart " {
$d.XAxis.MaxValue | Should be 361 $d.XAxis.MaxValue | Should be 361
$d.XAxis.MajorUnit | Should be 30 $d.XAxis.MajorUnit | Should be 30
@@ -794,6 +809,9 @@ Describe ExportExcel {
$d.ChartType.tostring() | Should be "line" $d.ChartType.tostring() | Should be "line"
$d.From.Column | Should be 2 $d.From.Column | Should be 2
} }
It "Appplied conditional formatting to the data " {
$ws.ConditionalFormatting[0].Formula | Should be "B1"
}
Close-ExcelPackage -ExcelPackage $excel -nosave Close-ExcelPackage -ExcelPackage $excel -nosave
} }
@@ -816,7 +834,7 @@ Describe ExportExcel {
$ct.ConditionalType | Should be "ContainsText" $ct.ConditionalType | Should be "ContainsText"
$ct.Text | Should be "Microsoft" $ct.Text | Should be "Microsoft"
} }
#Test -ConditionalFormat & -ConditionalText
Export-Excel -Path $path -ConditionalFormat $cf -ConditionalText $ct Export-Excel -Path $path -ConditionalFormat $cf -ConditionalText $ct
$excel = Open-ExcelPackage -Path $path $excel = Open-ExcelPackage -Path $path
$rows = $range -replace "^.*?(\d+)$", '$1' $rows = $range -replace "^.*?(\d+)$", '$1'
@@ -837,6 +855,7 @@ Describe ExportExcel {
Context " # Awkward multiple tables" { Context " # Awkward multiple tables" {
$path = "$Env:TEMP\test.xlsx" $path = "$Env:TEMP\test.xlsx"
#Test creating 3 on overlapping tables on the same page. Create rightmost the left most then middle.
remove-item -Path $path -ErrorAction SilentlyContinue remove-item -Path $path -ErrorAction SilentlyContinue
$r = Get-ChildItem -path C:\WINDOWS\system32 -File $r = Get-ChildItem -path C:\WINDOWS\system32 -File