diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index cff512a..ebfbf2e 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -51,7 +51,8 @@ function Export-Excel { [Switch]$KillExcel, [Switch]$AutoNameRange, $StartRow=1, - $StartColumn=1 + $StartColumn=1, + [Switch]$PassThru ) Begin { @@ -360,9 +361,13 @@ function Export-Excel { } } - $pkg.Save() - $pkg.Dispose() + if($PassThru) { + $pkg + } else { + $pkg.Save() + $pkg.Dispose() - if($Show) {Invoke-Item $Path} + if($Show) {Invoke-Item $Path} + } } } diff --git a/README.md b/README.md index d6f6088..9a6a0c3 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,35 @@ To install in your personal modules folder (e.g. ~\Documents\WindowsPowerShell\M iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfinke/ImportExcel/master/Install.ps1') ``` +## Try *PassThru* + +```powershell +$file = "C:\Temp\passthru.xlsx" +rm $file -ErrorAction Ignore + +$xlPkg = $( + New-PSItem north 10 + New-PSItem east 20 + New-PSItem west 30 + New-PSItem south 40 +) | Export-Excel $file -PassThru + + +$ws=$xlPkg.Workbook.Worksheets[1] + +$ws.Cells["A3"].Value = "Hello World" +$ws.Cells["B3"].Value = "Updating cells" +$ws.Cells["D1:D5"].Value = "Data" + +$ws.Cells.AutoFitColumns() + +$xlPkg.Save() +$xlPkg.Dispose() + +Invoke-Item $file +``` + + Known Issues - * Using `-IncludePivotTable`, if that pivot table name exists, you'll get an error.