diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 22a3ad4..a5e4970 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -43,78 +43,37 @@ function Import-Excel { } } -function Export-ExcelSheet { - - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [String] - $Path, - [String] - $OutputPath = '.\', - [String] - $SheetName, - [string] - $Encoding = 'UTF8', - [string] - $Extension = '.txt', - [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.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 - } -} - function Import-ExcelAllSheet { - [CmdletBinding()] - param - ( - [Parameter(Mandatory = $true)] - [String] - $Path, - [String] - $OutputPath = '.\', - [string] - $Encoding = 'UTF8', - [string] - $Extension = '.txt', - [string] - $Delimiter = ';' - ) - - $FullName = (Resolve-Path $Path).Path - $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $FullName - $workbook = $xl.Workbook - - - Foreach ($sheet in $workbook.Worksheets) - { - Write-Verbose "Exporting sheet: $($sheet.name)" - - Import-Excel -FullName $FullName -Sheet $($sheet.Name) | Export-Csv -Path "$($OutputPath)\$($Sheet.Name)$($Extension)" -Delimiter $Delimiter -NoTypeInformation -Encoding $Encoding - - } - + [CmdletBinding()] + param + ( + [Parameter(Mandatory = $true)] + [String] + $Path, + [String] + $OutputPath = '.\', + [string] + $Encoding = 'UTF8', + [string] + $Extension = '.txt', + [string] + $Delimiter = ';' + ) + + $FullName = (Resolve-Path $Path).Path + $xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $FullName + $workbook = $xl.Workbook + + + Foreach ($sheet in $workbook.Worksheets) + { + Write-Verbose "Exporting sheet: $($sheet.name)" + + Import-Excel -FullName $FullName -Sheet $($sheet.Name) | Export-Csv -Path "$($OutputPath)\$($Sheet.Name)$($Extension)" -Delimiter $Delimiter -NoTypeInformation -Encoding $Encoding + + } + } function Export-Excel { diff --git a/TestSheets.xlsx b/TestSheets.xlsx deleted file mode 100644 index 7086adb..0000000 Binary files a/TestSheets.xlsx and /dev/null differ diff --git a/data/sheet10.txt b/data/sheet10.txt deleted file mode 100644 index 25ab43f..0000000 --- a/data/sheet10.txt +++ /dev/null @@ -1,3 +0,0 @@ -"sheet10" -"" -"sheet10" diff --git a/data/sheet20.txt b/data/sheet20.txt deleted file mode 100644 index 66f82c8..0000000 --- a/data/sheet20.txt +++ /dev/null @@ -1,3 +0,0 @@ -"sheet20" -"" -"sheet20"