From 221bc5d21521504e827d9491b56f5ca09274d50a Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 22 Dec 2016 12:01:16 -0500 Subject: [PATCH] updated --- Export-Excel.ps1 | 14 +++++++++++--- ImportExcel.psd1 | 2 +- README.md | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index a39717a..2df98bb 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -14,7 +14,7 @@ function Export-Excel { Get-Service | Export-Excel "c:\temp\test.xlsx" -Show -IncludePivotTable -PivotRows status -PivotData @{status='count'} #> param( - [Parameter(Mandatory=$true)] + #[Parameter(Mandatory=$true)] $Path, [Parameter(ValueFromPipeline=$true)] $TargetData, @@ -51,7 +51,6 @@ function Export-Excel { [Object[]]$ConditionalFormat, [Object[]]$ConditionalText, [Object[]]$ExcelChartDefinition, - # [Object[]]$CellStyle, [ScriptBlock]$CellStyleSB, [string[]]$HideSheet, [Switch]$KillExcel, @@ -59,7 +58,8 @@ function Export-Excel { $StartRow=1, $StartColumn=1, [Switch]$PassThru, - [string]$Numberformat="General" + [string]$Numberformat="General", + [Switch]$Now ) Begin { @@ -70,7 +70,15 @@ function Export-Excel { } try { + if($Now) { + $Path=[System.IO.Path]::GetTempFileName() -replace "\.tmp",".xlsx" + $Show=$true + $AutoSize=$true + $AutoFilter=$true + } + $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) + if (Test-Path $path) { Write-Debug "File `"$Path`" already exists" } diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 4273cfb..ee3037b 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. -ModuleVersion = '2.2.9' +ModuleVersion = '2.2.10' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/README.md b/README.md index 70e74ed..bb00262 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,37 @@ iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfi # What's new +#### 12/22/2016 +- Added `-Now` switch. This short cuts the process, automatically creating a temp file and enables the `-Show`, `-AutoFilter`, `-AutoSize` switches. + +```powershell +Get-Process | Select Company, Handles | Export-Excel -Now +``` + +- Added ScriptBlocks for coloring cells. Check out + +```powershell +Get-Process | + Select-Object Company,Handles,PM, NPM| + Export-Excel $xlfile -Show -AutoSize -CellStyleSB { + param( + $workSheet, + $totalRows, + $lastColumn + ) + + Set-CellStyle $workSheet 1 $LastColumn Solid Cyan + + foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 0})) { + Set-CellStyle $workSheet $row $LastColumn Solid Gray + } + + foreach($row in (2..$totalRows | Where-Object {$_ % 2 -eq 1})) { + Set-CellStyle $workSheet $row $LastColumn Solid LightGray + } + } +``` + #### 9/28/2016 [Fixed](https://github.com/dfinke/ImportExcel/pull/126) Powershell 3.0 compatibility. Thanks to [headsphere](https://github.com/headsphere). He used `$obj.PSObject.Methods[$target]` snytax to make it backward compatible. PS v4.0 and later allow `$obj.$target`.