mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merged ValidateSet for Encoding and Extension
This commit is contained in:
@@ -2,6 +2,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
|
||||
|
||||
. $PSScriptRoot\Export-Excel.ps1
|
||||
. $PSScriptRoot\New-ConditionalFormattingIconSet.ps1
|
||||
. $PSScriptRoot\Export-ExcelSheet.ps1
|
||||
|
||||
function Import-Excel {
|
||||
param(
|
||||
@@ -52,53 +53,6 @@ function Import-Excel {
|
||||
}
|
||||
}
|
||||
|
||||
function Export-ExcelSheet {
|
||||
|
||||
[CmdletBinding()]
|
||||
param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[String]
|
||||
$Path,
|
||||
[String]
|
||||
$OutputPath = '.\',
|
||||
[String]
|
||||
$SheetName,
|
||||
[ValidateSet('ASCII', 'BigEndianUniCode','Default','OEM','UniCode','UTF32','UTF7','UTF8')]
|
||||
[string]
|
||||
$Encoding = 'UTF8',
|
||||
[ValidateSet('.txt', '.log','.csv')]
|
||||
[string]
|
||||
$Extension = '.csv',
|
||||
[ValidateSet(';', ',')]
|
||||
[string]
|
||||
$Delimiter = ';'
|
||||
)
|
||||
|
||||
$Path = (Resolve-Path $Path).Path
|
||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path
|
||||
$workbook = $xl.Workbook
|
||||
|
||||
$targetSheets = $workbook.Worksheets | Where {$_.Name -Match $SheetName}
|
||||
|
||||
$params = @{} + $PSBoundParameters
|
||||
$params.Remove("OutputPath")
|
||||
$params.Remove("SheetName")
|
||||
$params.Remove('Extension')
|
||||
$params.NoTypeInformation = $true
|
||||
|
||||
Foreach ($sheet in $targetSheets)
|
||||
{
|
||||
Write-Verbose "Exporting sheet: $($sheet.Name)"
|
||||
|
||||
$params.Path = "$OutputPath\$($Sheet.Name)$Extension"
|
||||
|
||||
Import-Excel $Path -Sheet $($sheet.Name) | Export-Csv @params
|
||||
}
|
||||
|
||||
$xl.Dispose()
|
||||
}
|
||||
|
||||
function Add-WorkSheet {
|
||||
param(
|
||||
#TODO Use parametersets to allow a workbook to be passed instead of a package
|
||||
|
||||
Reference in New Issue
Block a user