From 6bf16f75f733d258c32661c5276c62b894e0caac Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 16 Feb 2020 16:37:27 -0500 Subject: [PATCH 1/2] Create MultipleWorksheets.ps1 The PS commands to create an Excel file with multiple worksheets and adding one using ExcelPackage functions. --- Examples/MultipleWorksheets.ps1 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Examples/MultipleWorksheets.ps1 diff --git a/Examples/MultipleWorksheets.ps1 b/Examples/MultipleWorksheets.ps1 new file mode 100644 index 0000000..c7b2f6b --- /dev/null +++ b/Examples/MultipleWorksheets.ps1 @@ -0,0 +1,27 @@ +<# + To see this written up with example screenshots, head over to the IT Splat blog + URL: http://bit.ly/2SxieeM +#> + +## Create an Excel file with multiple worksheets +# Get a list of processes on the system +$processes = Get-Process | Sort-Object -Property ProcessName | Group-Object -Property ProcessName | Where-Object {$_.Count -gt 2} + +# Export the processes to Excel, each process on its own sheet +$processes | ForEach-Object { $_.Group | Export-Excel -Path MultiSheetExample.xlsx -WorksheetName $_.Name -AutoSize -AutoFilter } + +# Show the completed file +Invoke-Item .\MultiSheetExample.xlsx + +## Add an additional sheet to the new workbook +# Use Open-ExcelPackage to open the workbook +$excelPackage = Open-ExcelPackage -Path .\MultiSheetExample.xlsx + +# Create a new worksheet and give it a name, set MoveToStart to make it the first sheet +$ws = Add-Worksheet -ExcelPackage $excelPackage -WorksheetName 'All Services' -MoveToStart + +# Get all the running services on the system +Get-Service | Export-Excel -ExcelPackage $excelPackage -WorksheetName $ws -AutoSize -AutoFilter + +# Close the package and show the final result +Close-ExcelPackage -ExcelPackage $excelPackage -Show From 59e31d54a7444f354badb4af20b86d67622443ce Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 18 Feb 2020 09:02:49 -0500 Subject: [PATCH 2/2] Move to /Examples/CommunityContributions Folder --- Examples/{ => CommunityContributions}/MultipleWorksheets.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Examples/{ => CommunityContributions}/MultipleWorksheets.ps1 (100%) diff --git a/Examples/MultipleWorksheets.ps1 b/Examples/CommunityContributions/MultipleWorksheets.ps1 similarity index 100% rename from Examples/MultipleWorksheets.ps1 rename to Examples/CommunityContributions/MultipleWorksheets.ps1