From e6c8380c587ef6c4e2ec80e75d927e35265f2a44 Mon Sep 17 00:00:00 2001 From: Doug Finke Date: Fri, 10 Apr 2015 10:02:33 -0400 Subject: [PATCH] Added Export-MultipleExcelSheets --- ImportExcel.psm1 | 28 +++++++++++++++++++++++++++- test.ps1 | 10 ++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test.ps1 diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 275438e..fc0867a 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -143,4 +143,30 @@ function Export-Excel { if($Show) {Invoke-Item $Path} } -} \ No newline at end of file +} + +function Export-MultipleExcelSheets { + param( + [Parameter(Mandatory)] + $Path, + [Parameter(Mandatory)] + [hashtable]$InfoMap, + [Switch]$Show, + [Switch]$AutoSize + ) + + $parameters = @{}+$PSBoundParameters + $parameters.Remove("InfoMap") + $parameters.Remove("Show") + + $parameters.Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) + + foreach ($entry in $InfoMap.GetEnumerator()) { + Write-Progress -Activity "Exporting" -Status "$($entry.Key)" + $parameters.WorkSheetname=$entry.Key + + & $entry.Value | Export-Excel @parameters + } + + if($Show) {Invoke-Item $Path} +} diff --git a/test.ps1 b/test.ps1 new file mode 100644 index 0000000..633f855 --- /dev/null +++ b/test.ps1 @@ -0,0 +1,10 @@ +cls + +$DataToGather = @{ + Processes = {ps} + Services = {gsv} + Files = {dir -File} + Albums = {(Invoke-RestMethod http://www.dougfinke.com/powershellfordevelopers/albums.js)} +} + +Export-MultipleExcelSheets -Show -AutoSize .\testExport.xlsx $DataToGather \ No newline at end of file