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