Added -PivotTableName to export excel (see also Readme.md)

This commit is contained in:
jhoneill
2018-06-28 12:14:13 +01:00
parent a3693a7faf
commit 6c24db9593
3 changed files with 26 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Module $here -Force
Import-Module $here -Force -Verbose
if (Get-process -Name Excel,xlim -ErrorAction SilentlyContinue) { Write-Warning -Message "You need to close Excel before running the tests." ; return}
Describe ExportExcel {
@@ -453,12 +453,12 @@ Describe ExportExcel {
$path = "$env:TEMP\Test.xlsx"
#Catch warning
$warnVar = $null
#Test Append with no existing sheet.
get-process | Select-Object -first 10 -Property Name,cpu,pm,handles,company | export-excel -StartRow 3 -StartColumn 3 -AutoFilter -AutoNameRange -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -Path $path -WorkSheetname withOffset -append
get-process | Select-Object -last 10 -Property Name,cpu,pm,handles,company | export-excel -StartRow 3 -StartColumn 3 -AutoFilter -AutoNameRange -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -Path $path -WorkSheetname withOffset -append -WarningAction SilentlyContinue -WarningVariable warnvar
#Test Append with no existing sheet. Test adding a named pivot table from a command line parameter
get-process | Select-Object -first 10 -Property Name,cpu,pm,handles,company | export-excel -StartRow 3 -StartColumn 3 -AutoFilter -AutoNameRange -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -append
get-process | Select-Object -last 10 -Property Name,cpu,pm,handles,company | export-excel -StartRow 3 -StartColumn 3 -AutoFilter -AutoNameRange -BoldTopRow -IncludePivotTable -PivotRows Company -PivotData PM -PivotTableName 'PTOffset' -Path $path -WorkSheetname withOffset -append -WarningAction SilentlyContinue -WarningVariable warnvar
$Excel = Open-ExcelPackage $path
$dataWs = $Excel.Workbook.Worksheets["withOffset"]
$pt = $Excel.Workbook.Worksheets["withOffsetPivotTable"].PivotTables[0]
$pt = $Excel.Workbook.Worksheets["PTOffset"].PivotTables[0]
it "Created and appended to a sheet offset from the top left corner " {
$dataWs.Cells[1,1].Value | Should beNullOrEmpty
$dataWs.Cells[2,2].Value | Should beNullOrEmpty
@@ -479,7 +479,6 @@ Describe ExportExcel {
Context "#Example 11 # Create and append with title, inc ranges and Pivot table" {
$path = "$env:TEMP\Test.xlsx"
#Catch warning
$ptDef = [ordered]@{}
$ptDef += New-PivotTableDefinition -PivotTableName "PT1" -SourceWorkSheet 'Sheet1' -PivotRows "Status" -PivotData @{'Status' = 'Count'} -PivotFilter "StartType" -IncludePivotChart -ChartType BarClustered3D -ChartTitle "Services by status" -ChartHeight 512 -ChartWidth 768 -ChartRow 10 -ChartColumn 0 -NoLegend
$ptDef += New-PivotTableDefinition -PivotTableName "PT2" -SourceWorkSheet 'Sheet2' -PivotRows "Company" -PivotData @{'Company' = 'Count'} -IncludePivotChart -ChartType PieExploded3D -ShowPercent -WarningAction SilentlyContinue
@@ -493,6 +492,7 @@ Describe ExportExcel {
$ptDef.PT1.ChartType.tostring() | Should be 'BarClustered3D'
}
Remove-Item -Path $path
#Catch warning
$warnvar = $null
Get-Service | Select-Object -Property Status, Name, DisplayName, StartType | 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

View File

@@ -354,6 +354,7 @@
[Int]$TitleSize = 22,
[System.Drawing.Color]$TitleBackgroundColor,
[Switch]$IncludePivotTable,
[String]$PivotTableName,
[String[]]$PivotRows,
[String[]]$PivotColumns,
$PivotData,
@@ -730,9 +731,10 @@
}
if ($IncludePivotTable -or $IncludePivotChart) {
$params = @{
"PivotTableName" = ($WorkSheetname + 'PivotTable') ;
"SourceRange" = $dataRange
}
if ($PivotTableName) {$params.PivotTableName = $PivotTableName}
else {$params.PivotTableName = $WorkSheetname + 'PivotTable'}
if ($PivotFilter) {$params.PivotFilter = $PivotFilter}
if ($PivotRows) {$params.PivotRows = $PivotRows}
if ($PivotColumns) {$Params.PivotColumns = $PivotColumns}

View File

@@ -61,6 +61,7 @@ iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfi
- Removed the need to specify a fill type when specifying a title background color
- Added MoveToStart, MoveToEnd, MoveBefore and MoveAfter Parameters - these go straight through to Add worksheet
- Added "NoScriptOrAliasProperties" "DisplayPropertySet" switches (names subject to change) - combined with ExcludeProperty these are a quick way to reduce the data exported (and speed things up)
- Added PivotTableName Switch (in line with 5.0.1 release)
- Add-CellValue now understands URI item properties. If a property is of type URI it is created as a hyperlink to speed up Add-CellValue
- Commented out the write verbose statements even if verbose is silenced they cause a significiant performance impact and if it's on they will cause a flood of messages.
- Re-ordered the choices in the switch and added an option to say "If it is numeric already post it as is"