From 3eac21c11ab5193ce0e5cddf5d610e3972610164 Mon Sep 17 00:00:00 2001 From: Irwin Strachan Date: Thu, 1 Oct 2015 12:12:52 +0200 Subject: [PATCH] Update ImportExcel.psm1 Created a ValidateSet for Encoding and Extension. removed Extension from the params. Removed Encoding at the Export-Csv as it is already included in params --- ImportExcel.psm1 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 9343707..5e2bce3 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -64,10 +64,13 @@ function Export-ExcelSheet { $OutputPath = '.\', [String] $SheetName, + [ValidateSet('ASCII', 'BigEndianUniCode','Default','OEM','UniCode','UTF32','UTF7','UTF8')] [string] $Encoding = 'UTF8', + [ValidateSet('.txt', '.log','.csv')] [string] - $Extension = '.txt', + $Extension = '.csv', + [ValidateSet(';', ',')] [string] $Delimiter = ';' ) @@ -81,6 +84,7 @@ function Export-ExcelSheet { $params = @{} + $PSBoundParameters $params.Remove("OutputPath") $params.Remove("SheetName") + $params.Remove('Extension') $params.NoTypeInformation = $true Foreach ($sheet in $targetSheets) @@ -89,7 +93,7 @@ function Export-ExcelSheet { $params.Path = "$OutputPath\$($Sheet.Name)$Extension" - Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding + Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params } $xl.Dispose() @@ -142,10 +146,13 @@ function ConvertFrom-ExcelSheet { $OutputPath = '.\', [String] $SheetName="*", + [ValidateSet('ASCII', 'BigEndianUniCode','Default','OEM','UniCode','UTF32','UTF7','UTF8')] [string] $Encoding = 'UTF8', + [ValidateSet('.txt', '.log','.csv')] [string] - $Extension = '.txt', + $Extension = '.csv', + [ValidateSet(';', ',')] [string] $Delimiter = ';' ) @@ -160,6 +167,7 @@ function ConvertFrom-ExcelSheet { $params = @{} + $PSBoundParameters $params.Remove("OutputPath") $params.Remove("SheetName") + $params.Remove('Extension') $params.NoTypeInformation = $true Foreach ($sheet in $targetSheets) @@ -168,7 +176,7 @@ function ConvertFrom-ExcelSheet { $params.Path = "$OutputPath\$($Sheet.Name)$Extension" - Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params -Encoding $Encoding + Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params } $stream.Close() @@ -201,4 +209,4 @@ function Export-MultipleExcelSheets { } if($Show) {Invoke-Item $Path} -} \ No newline at end of file +}