From 8151ed4305f4fc8b1c82c457b3f90c75c89dea23 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 23 May 2020 17:06:12 -0400 Subject: [PATCH 1/6] Remove help file --- Public/Export-MultipleExcelSheets.md | 120 --------------------------- 1 file changed, 120 deletions(-) delete mode 100644 Public/Export-MultipleExcelSheets.md diff --git a/Public/Export-MultipleExcelSheets.md b/Public/Export-MultipleExcelSheets.md deleted file mode 100644 index e30679b..0000000 --- a/Public/Export-MultipleExcelSheets.md +++ /dev/null @@ -1,120 +0,0 @@ ---- -external help file: ImportExcel-help.xml -Module Name: ImportExcel -online version: https://github.com/dfinke/ImportExcel -schema: 2.0.0 ---- - -# Export-MultipleExcelSheets - -## SYNOPSIS -{{ Fill in the Synopsis }} - -## SYNTAX - -``` -Export-MultipleExcelSheets [-Path] [-InfoMap] [[-Password] ] [-Show] [-AutoSize] [] -``` - -## DESCRIPTION -{{ Fill in the Description }} - -## EXAMPLES - -### Example 1 -```powershell -PS C:\> {{ Add example code here }} -``` - -{{ Add example description here }} - -## PARAMETERS - -### -AutoSize -{{ Fill AutoSize Description }} - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -InfoMap -{{ Fill InfoMap Description }} - -```yaml -Type: Hashtable -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Password -{{ Fill Password Description }} - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Path -{{ Fill Path Description }} - -```yaml -Type: Object -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Show -{{ Fill Show Description }} - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### None - -## OUTPUTS - -### System.Object -## NOTES - -## RELATED LINKS From c4b3556c5d3df42ba9aa1bb34fefbd3ce5aed07c Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 23 May 2020 17:06:45 -0400 Subject: [PATCH 2/6] Don't source the Export-Multiplesheets ps1 --- ImportExcel.psd1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 649518d..e8c6d6d 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -50,8 +50,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'DoChart', 'Expand-NumberFormat', 'Export-Excel', - 'Export-ExcelSheet', - 'Export-MultipleExcelSheets', + 'Export-ExcelSheet', 'Get-ExcelColumnName', 'Get-ExcelSheetInfo', 'Get-ExcelWorkbookInfo', From 070d40b5afaa61e174fdfdbdc77ac4e78c2faf7f Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 23 May 2020 17:10:54 -0400 Subject: [PATCH 3/6] Move to Examples/Experimental --- {Public => Examples/Experimental}/Export-MultipleExcelSheets.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Public => Examples/Experimental}/Export-MultipleExcelSheets.ps1 (100%) diff --git a/Public/Export-MultipleExcelSheets.ps1 b/Examples/Experimental/Export-MultipleExcelSheets.ps1 similarity index 100% rename from Public/Export-MultipleExcelSheets.ps1 rename to Examples/Experimental/Export-MultipleExcelSheets.ps1 From a5a98d5c926ed5b81a338febdf0372e0e71a7e67 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 23 May 2020 17:32:03 -0400 Subject: [PATCH 4/6] Used to drive the Export-MultipleExcelSheets --- .../tryExportMultipleExcelSheets.ps1 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Examples/Experimental/tryExportMultipleExcelSheets.ps1 diff --git a/Examples/Experimental/tryExportMultipleExcelSheets.ps1 b/Examples/Experimental/tryExportMultipleExcelSheets.ps1 new file mode 100644 index 0000000..7ccbd00 --- /dev/null +++ b/Examples/Experimental/tryExportMultipleExcelSheets.ps1 @@ -0,0 +1,17 @@ +. "$PSScriptRoot\Export-MultipleExcelSheets.ps1" + +$xlfile = "$env:TEMP\test.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$p = Get-Process + +$InfoMap = @{ + PM = { $p | Select-Object company, pm } + Handles = { $p | Select-Object company, handles } + Services = { Get-Service } + Files = { Get-ChildItem -File } + Albums = { ConvertFrom-Csv (Invoke-RestMethod https://raw.githubusercontent.com/dfinke/powershell-for-developers/master/chapter05/BeaverMusic/BeaverMusic.UI.Shell/albums.csv) } + WillNotGetExported = "Hello World" +} + +Export-MultipleExcelSheets -Path $xlfile -InfoMap $InfoMap -Show -AutoSize \ No newline at end of file From 001aabf52694c48cf227c77f45ecc7ebc50962ae Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 23 May 2020 17:32:22 -0400 Subject: [PATCH 5/6] Added synopsis, and tests the value is a scriptblock --- .../Export-MultipleExcelSheets.ps1 | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Examples/Experimental/Export-MultipleExcelSheets.ps1 b/Examples/Experimental/Export-MultipleExcelSheets.ps1 index 80ce9f9..a922b44 100644 --- a/Examples/Experimental/Export-MultipleExcelSheets.ps1 +++ b/Examples/Experimental/Export-MultipleExcelSheets.ps1 @@ -1,6 +1,19 @@ function Export-MultipleExcelSheets { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")] + <# + .Synopsis + Takes a hash table of scriptblocks and exports each as a sheet in an Excel file + + .Example +$p = Get-Process + +$InfoMap = @{ + PM = { $p | Select-Object company, pm } + Handles = { $p | Select-Object company, handles } + Services = { Get-Service } +} + +Export-MultipleExcelSheets -Path $xlfile -InfoMap $InfoMap -Show -AutoSize + #> param( [Parameter(Mandatory = $true)] $Path, @@ -18,10 +31,15 @@ function Export-MultipleExcelSheets { $parameters.Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) foreach ($entry in $InfoMap.GetEnumerator()) { - Write-Progress -Activity "Exporting" -Status "$($entry.Key)" - $parameters.WorkSheetname = $entry.Key + if ($entry.Value -is [scriptblock]) { + Write-Progress -Activity "Exporting" -Status "$($entry.Key)" + $parameters.WorkSheetname = $entry.Key - & $entry.Value | Export-Excel @parameters + & $entry.Value | Export-Excel @parameters + } + else { + Write-Warning "$($entry.Key) not exported, needs to be a scriptblock" + } } if ($Show) { Invoke-Item $Path } From 51b23323fad49442e67c3104ef2db0e737897249 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 24 May 2020 10:59:57 -0400 Subject: [PATCH 6/6] Scrub invalid chars from the filename --- CI/CI.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/CI/CI.ps1 b/CI/CI.ps1 index 5f88bc2..d27a83f 100644 --- a/CI/CI.ps1 +++ b/CI/CI.ps1 @@ -131,6 +131,7 @@ if ($Artifact) { "[Progress] Artifact Start for Module: $ModuleName, Version: $VersionLocal." if ($env:APPVEYOR) { $ZipFileName = "{0} {1} {2} {3:yyyy-MM-dd HH-mm-ss}.zip" -f $ModuleName, $VersionLocal, $env:APPVEYOR_REPO_BRANCH, (Get-Date) + $ZipFileName = $ZipFileName -replace ("[{0}]" -f [RegEx]::Escape([IO.Path]::GetInvalidFileNameChars() -join '')) $ZipFileFullPath = Join-Path -Path $PSScriptRoot -ChildPath $ZipFileName "[Info] Artifact. $ModuleName, ZipFileName: $ZipFileName." #Compress-Archive -Path $ModulePath -DestinationPath $ZipFileFullPath