mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-02-24 16:42:47 +00:00
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
This commit is contained in:
@@ -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}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user