Fix spelling for GroupNumber* params

This commit is contained in:
dfinke
2018-12-07 14:33:38 -05:00
parent e4deb5801e
commit 69f9ba7d17

View File

@@ -84,7 +84,7 @@
into the same column as location. into the same column as location.
Finally the workbook is saved and shown in Excel. Finally the workbook is saved and shown in Excel.
#> #>
[cmdletbinding(defaultParameterSetName='ChartbyParams')] [cmdletbinding(defaultParameterSetName = 'ChartbyParams')]
[OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])]
param ( param (
#Name for the new PivotTable - this will be the name of a sheet in the Workbook. #Name for the new PivotTable - this will be the name of a sheet in the Workbook.
@@ -111,7 +111,7 @@
#If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns. #If there are multiple data items in a PivotTable, by default they are shown on separate rows; this switch makes them separate columns.
[Switch]$PivotDataToColumn, [Switch]$PivotDataToColumn,
#Define whether totals should be added to rows, columns neither, or both (the default is both). #Define whether totals should be added to rows, columns neither, or both (the default is both).
[ValidateSet("Both","Columns","Rows","None")] [ValidateSet("Both", "Columns", "Rows", "None")]
[String]$PivotTotals = "Both", [String]$PivotTotals = "Both",
#Included for compatibility - equivalent to -PivotTotals "None". #Included for compatibility - equivalent to -PivotTotals "None".
[Switch]$NoTotalsInPivot, [Switch]$NoTotalsInPivot,
@@ -122,53 +122,53 @@
#The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 )
[String]$GroupNumericRow, [String]$GroupNumericRow,
#The starting point for grouping #The starting point for grouping
[double]$GroupNumbericMin = 0 , [double]$GroupNumericMin = 0 ,
#The endpoint for grouping #The endpoint for grouping
[double]$GroupNumbericMax = [Double]::MaxValue , [double]$GroupNumericMax = [Double]::MaxValue ,
#The interval for grouping #The interval for grouping
[double]$GroupNumbericInterval = 100 , [double]$GroupNumericInterval = 100 ,
#Number format to apply to the data cells in the PivotTable. #Number format to apply to the data cells in the PivotTable.
[string]$PivotNumberFormat, [string]$PivotNumberFormat,
#Apply a table style to the PivotTable. #Apply a table style to the PivotTable.
[OfficeOpenXml.Table.TableStyles]$PivotTableStyle, [OfficeOpenXml.Table.TableStyles]$PivotTableStyle,
#Use a chart definition instead of specifying chart settings one by one. #Use a chart definition instead of specifying chart settings one by one.
[Parameter(ParameterSetName='ChartbyDef', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
$PivotChartDefinition, $PivotChartDefinition,
#If specified, a chart will be included. #If specified, a chart will be included.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$IncludePivotChart, [Switch]$IncludePivotChart,
#Optional title for the pivot chart, by default the title omitted. #Optional title for the pivot chart, by default the title omitted.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[String]$ChartTitle = "", [String]$ChartTitle = "",
#Height of the chart in Pixels (400 by default). #Height of the chart in Pixels (400 by default).
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[int]$ChartHeight = 400 , [int]$ChartHeight = 400 ,
#Width of the chart in Pixels (600 by default). #Width of the chart in Pixels (600 by default).
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[int]$ChartWidth = 600, [int]$ChartWidth = 600,
#Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). #Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1).
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartRow = 0 , [Int]$ChartRow = 0 ,
#Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E). #Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E).
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartColumn = 4, [Int]$ChartColumn = 4,
#Vertical offset of the chart from the cell corner. #Vertical offset of the chart from the cell corner.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartRowOffSetPixels = 0 , [Int]$ChartRowOffSetPixels = 0 ,
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
#Horizontal offset of the chart from the cell corner. #Horizontal offset of the chart from the cell corner.
[Int]$ChartColumnOffSetPixels = 0, [Int]$ChartColumnOffSetPixels = 0,
#Type of chart; defaults to "Pie". #Type of chart; defaults to "Pie".
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie',
#If specified hides the chart legend. #If specified hides the chart legend.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$NoLegend, [Switch]$NoLegend,
#If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. #If specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$ShowCategory, [Switch]$ShowCategory,
#If specified attaches percentages to slices in a pie chart. #If specified attaches percentages to slices in a pie chart.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$ShowPercent, [Switch]$ShowPercent,
#If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified. #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified.
[switch]$Activate, [switch]$Activate,
@@ -177,7 +177,7 @@
) )
if ($PivotTableName.length -gt 250) { if ($PivotTableName.length -gt 250) {
Write-warning -Message "PivotTable name will be truncated" Write-warning -Message "PivotTable name will be truncated"
$PivotTableName = $PivotTableName.Substring(0,250) $PivotTableName = $PivotTableName.Substring(0, 250)
} }
if ($Address) { if ($Address) {
[OfficeOpenXml.ExcelWorksheet]$wsPivot = $address.Worksheet [OfficeOpenXml.ExcelWorksheet]$wsPivot = $address.Worksheet
@@ -214,7 +214,7 @@
Write-Warning -Message "Could not find source Worksheet for pivot-table '$pivotTableName'." ; return Write-Warning -Message "Could not find source Worksheet for pivot-table '$pivotTableName'." ; return
} }
elseif ( $SourceRange -is [String] -or $SourceRange -is [OfficeOpenXml.ExcelAddress]) { elseif ( $SourceRange -is [String] -or $SourceRange -is [OfficeOpenXml.ExcelAddress]) {
$pivotTable = $wsPivot.PivotTables.Add($Address,$SourceWorkSheet.Cells[$SourceRange], $pivotTableName) $pivotTable = $wsPivot.PivotTables.Add($Address, $SourceWorkSheet.Cells[$SourceRange], $pivotTableName)
} }
else {Write-warning "Could not create a PivotTable with the Source Range provided."; return} else {Write-warning "Could not create a PivotTable with the Source Range provided."; return}
foreach ($Row in $PivotRows) { foreach ($Row in $PivotRows) {
@@ -256,12 +256,12 @@
if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false } if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false }
if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle} if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle}
if ($GroupNumericRow) { if ($GroupNumericRow) {
$r =$pivotTable.RowFields.Where({$_.name -eq $GroupNumericRow }) $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupNumericRow })
if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupNumericRow'; no numeric grouping will be done."} if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupNumericRow'; no numeric grouping will be done."}
else {$r.AddNumericGrouping($GroupNumbericMin,$GroupNumbericMax,$GroupNumbericInterval)} else {$r.AddNumericGrouping($GroupNumericMin, $GroupNumericMax, $GroupNumericInterval)}
} }
if ($GroupDateRow -and $PSBoundParameters.ContainsKey("GroupDatePart")) { if ($GroupDateRow -and $PSBoundParameters.ContainsKey("GroupDatePart")) {
$r =$pivotTable.RowFields.Where({$_.name -eq $GroupDateRow }) $r = $pivotTable.RowFields.Where( {$_.name -eq $GroupDateRow })
if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupDateRow'; no date grouping will be done."} if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupDateRow'; no date grouping will be done."}
else {$r.AddDateGrouping($GroupDatePart)} else {$r.AddDateGrouping($GroupDatePart)}
} }
@@ -282,11 +282,11 @@
} }
elseif ($PivotChartDefinition -and -not $wsPivot.Drawings["Chart$pivotTableName"]) { elseif ($PivotChartDefinition -and -not $wsPivot.Drawings["Chart$pivotTableName"]) {
if ($PivotChartDefinition -is [System.Management.Automation.PSCustomObject]) { if ($PivotChartDefinition -is [System.Management.Automation.PSCustomObject]) {
$params = @{PivotTable= $pivotTable } $params = @{PivotTable = $pivotTable }
$PivotChartDefinition.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}} $PivotChartDefinition.PSObject.Properties | ForEach-Object {if ( $null -ne $_.value) {$params[$_.name] = $_.value}}
Add-ExcelChart @params Add-ExcelChart @params
} }
elseif ($PivotChartDefinition -is [hashtable] -or $PivotChartDefinition -is[System.Collections.Specialized.OrderedDictionary]) { elseif ($PivotChartDefinition -is [hashtable] -or $PivotChartDefinition -is [System.Collections.Specialized.OrderedDictionary]) {
Add-ExcelChart -PivotTable $pivotTable @PivotChartDefinition Add-ExcelChart -PivotTable $pivotTable @PivotChartDefinition
} }
} }
@@ -333,7 +333,7 @@ function New-PivotTableDefinition {
[Switch]$PivotDataToColumn, [Switch]$PivotDataToColumn,
#By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected. #By default PivotTables have Totals for each Row (on the right) and for each column at the bottom. This allows just one or neither to be selected.
#Define whther totals should be added to rows, columns neither, or both (the default is both) #Define whther totals should be added to rows, columns neither, or both (the default is both)
[ValidateSet("Both","Columns","Rows","None")] [ValidateSet("Both", "Columns", "Rows", "None")]
[String]$PivotTotals = "Both", [String]$PivotTotals = "Both",
#Included for compatibility - equivalent to -PivotTotals "None" #Included for compatibility - equivalent to -PivotTotals "None"
[Switch]$NoTotalsInPivot, [Switch]$NoTotalsInPivot,
@@ -344,60 +344,60 @@ function New-PivotTableDefinition {
#The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 )
[String]$GroupNumericRow, [String]$GroupNumericRow,
#The starting point for grouping #The starting point for grouping
[double]$GroupNumbericMin = 0 , [double]$GroupNumericMin = 0 ,
#The endpoint for grouping #The endpoint for grouping
[double]$GroupNumbericMax = [Double]::MaxValue , [double]$GroupNumericMax = [Double]::MaxValue ,
#The interval for grouping #The interval for grouping
[double]$GroupNumbericInterval = 100 , [double]$GroupNumericInterval = 100 ,
#Number format to apply to the data cells in the PivotTable #Number format to apply to the data cells in the PivotTable
[string]$PivotNumberFormat, [string]$PivotNumberFormat,
#Apply a table style to the PivotTable #Apply a table style to the PivotTable
[OfficeOpenXml.Table.TableStyles]$PivotTableStyle, [OfficeOpenXml.Table.TableStyles]$PivotTableStyle,
#Use a chart definition instead of specifying chart settings one by one #Use a chart definition instead of specifying chart settings one by one
[Parameter(ParameterSetName='ChartbyDef', Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [Parameter(ParameterSetName = 'ChartbyDef', Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
$PivotChartDefinition, $PivotChartDefinition,
#If specified a chart Will be included. #If specified a chart Will be included.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$IncludePivotChart, [Switch]$IncludePivotChart,
#Optional title for the pivot chart, by default the title omitted. #Optional title for the pivot chart, by default the title omitted.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[String]$ChartTitle, [String]$ChartTitle,
#Height of the chart in Pixels (400 by default) #Height of the chart in Pixels (400 by default)
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[int]$ChartHeight = 400 , [int]$ChartHeight = 400 ,
#Width of the chart in Pixels (600 by default) #Width of the chart in Pixels (600 by default)
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[int]$ChartWidth = 600, [int]$ChartWidth = 600,
#Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1). #Cell position of the top left corner of the chart, there will be this number of rows above the top edge of the chart (default is 0, chart starts at top edge of row 1).
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartRow = 0 , [Int]$ChartRow = 0 ,
#Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E) #Cell position of the top left corner of the chart, there will be this number of cells to the left of the chart (default is 4, chart starts at left edge of column E)
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartColumn = 4, [Int]$ChartColumn = 4,
#Vertical offset of the chart from the cell corner. #Vertical offset of the chart from the cell corner.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartRowOffSetPixels = 0 , [Int]$ChartRowOffSetPixels = 0 ,
#Horizontal offset of the chart from the cell corner. #Horizontal offset of the chart from the cell corner.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Int]$ChartColumnOffSetPixels = 0, [Int]$ChartColumnOffSetPixels = 0,
#Type of chart #Type of chart
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie', [OfficeOpenXml.Drawing.Chart.eChartType]$ChartType = 'Pie',
#If specified hides the chart legend #If specified hides the chart legend
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$NoLegend, [Switch]$NoLegend,
#if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type. #if specified attaches the category to slices in a pie chart : not supported on all chart types, this may give errors if applied to an unsupported type.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$ShowCategory, [Switch]$ShowCategory,
#If specified attaches percentages to slices in a pie chart. #If specified attaches percentages to slices in a pie chart.
[Parameter(ParameterSetName='ChartbyParams')] [Parameter(ParameterSetName = 'ChartbyParams')]
[Switch]$ShowPercent, [Switch]$ShowPercent,
#If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified
[switch]$Activate [switch]$Activate
) )
$validDataFuntions = [system.enum]::GetNames([OfficeOpenXml.Table.PivotTable.DataFieldFunctions]) $validDataFuntions = [system.enum]::GetNames([OfficeOpenXml.Table.PivotTable.DataFieldFunctions])
if ($PivotData.values.Where({$_ -notin $validDataFuntions}) ) { if ($PivotData.values.Where( {$_ -notin $validDataFuntions}) ) {
Write-Warning -Message ("Pivot data functions might not be valid, they should be one of " + ($validDataFuntions -join ", ") + ".") Write-Warning -Message ("Pivot data functions might not be valid, they should be one of " + ($validDataFuntions -join ", ") + ".")
} }