diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 3e2dd1a..bc91dc0 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -513,6 +513,7 @@ #If there is already content in the workbook the sheet with the PivotTable will not be active UNLESS Activate is specified [switch]$Activate, [Parameter(ParameterSetName = 'Now')] + [Parameter(ParameterSetName = "Path")] [Switch]$Now, [Switch]$ReturnRange, #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. @@ -532,10 +533,12 @@ $script:Header = $null if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet."} if ($PSBoundParameters.Keys.Count -eq 0 -Or $Now -or (-not $Path -and -not $ExcelPackage) ) { - $Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx' - $Show = $true - $AutoSize = $true - if (-not $TableName) { + if (-not $PSBoundParameters.ContainsKey("Path")) { $Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx' } + if (-not $PSBoundParameters.ContainsKey("Show")) { $Show = $true } + if (-not $PSBoundParameters.ContainsKey("AutoSize")) { $AutoSize = $true } + if (-not $PSBoundParameters.ContainsKey("TableName") -and + -not $PSBoundParameters.ContainsKey("TableStyle") -and + -not $PSBoundParameters.ContainsKey("AutoFilter")) { $AutoFilter = $true } } diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 0cef410..d4bc052 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -109,6 +109,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'New-PSItem', 'NumberFormatCompletion', 'Open-ExcelPackage', + 'Out-Excel', 'PieChart', 'Pivot', 'Remove-WorkSheet' diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 4bdbb55..f7e3b9f 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -29,6 +29,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" . $PSScriptRoot\New-ExcelChart.ps1 . $PSScriptRoot\New-PSItem.ps1 . $PSScriptRoot\Open-ExcelPackage.ps1 +. $PSScriptRoot\Out-Excel.ps1 . $PSScriptRoot\Pivot.ps1 . $PSScriptRoot\PivotTable.ps1 . $PSScriptRoot\RemoveWorksheet.ps1 diff --git a/Out-Excel.ps1 b/Out-Excel.ps1 new file mode 100644 index 0000000..5c6cb2c --- /dev/null +++ b/Out-Excel.ps1 @@ -0,0 +1,54 @@ +Function Out-Excel { + [CmdletBinding(DefaultParameterSetName = 'Now')] + param() + #Import the parameters from Export-Excel. + DynamicParam { + $paramDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() + foreach ($P in (Get-Command -Name Export-Excel).Parameters.values.where( { $_.Name -notmatch 'Verbose|Debug|Action$|Variable$|Buffer$|Now' })) { + $paramDictionary.Add($P.Name, [System.Management.Automation.RuntimeDefinedParameter]::new( $P.Name, $P.ParameterType, $P.Attributes ) ) + } + return $paramDictionary + } + + begin { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { + $PSBoundParameters['OutBuffer'] = 1 + } + + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Export-Excel', [System.Management.Automation.CommandTypes]::Function) + $scriptCmd = { & $wrappedCmd @PSBoundParameters -Now } + + $steppablePipeline = $scriptCmd.GetSteppablePipeline() + $steppablePipeline.Begin($PSCmdlet) + } + catch { + throw + } + } + + process { + try { + $steppablePipeline.Process($_) + } + catch { + throw + } + } + + end { + try { + $steppablePipeline.End() + } + catch { + throw + } + } + <# + + .ForwardHelpTargetName Export-Excel + .ForwardHelpCategory Function + + #> +} \ No newline at end of file