mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Suggesting modifications
This commit is contained in:
@@ -43,37 +43,78 @@ 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
|
function Import-ExcelAllSheet
|
||||||
{
|
{
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param
|
param
|
||||||
(
|
(
|
||||||
[Parameter(Mandatory = $true)]
|
[Parameter(Mandatory = $true)]
|
||||||
[String]
|
[String]
|
||||||
$Path,
|
$Path,
|
||||||
[String]
|
[String]
|
||||||
$OutputPath = '.\',
|
$OutputPath = '.\',
|
||||||
[string]
|
[string]
|
||||||
$Encoding = 'UTF8',
|
$Encoding = 'UTF8',
|
||||||
[string]
|
[string]
|
||||||
$Extension = '.txt',
|
$Extension = '.txt',
|
||||||
[string]
|
[string]
|
||||||
$Delimiter = ';'
|
$Delimiter = ';'
|
||||||
)
|
)
|
||||||
|
|
||||||
$FullName = (Resolve-Path $Path).Path
|
$FullName = (Resolve-Path $Path).Path
|
||||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $FullName
|
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $FullName
|
||||||
$workbook = $xl.Workbook
|
$workbook = $xl.Workbook
|
||||||
|
|
||||||
|
|
||||||
Foreach ($sheet in $workbook.Worksheets)
|
Foreach ($sheet in $workbook.Worksheets)
|
||||||
{
|
{
|
||||||
Write-Verbose "Exporting sheet: $($sheet.name)"
|
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
|
Import-Excel -FullName $FullName -Sheet $($sheet.Name) | Export-Csv -Path "$($OutputPath)\$($Sheet.Name)$($Extension)" -Delimiter $Delimiter -NoTypeInformation -Encoding $Encoding
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Export-Excel {
|
function Export-Excel {
|
||||||
|
|||||||
BIN
TestSheets.xlsx
Normal file
BIN
TestSheets.xlsx
Normal file
Binary file not shown.
3
data/sheet10.txt
Normal file
3
data/sheet10.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"sheet10"
|
||||||
|
""
|
||||||
|
"sheet10"
|
||||||
3
data/sheet20.txt
Normal file
3
data/sheet20.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
"sheet20"
|
||||||
|
""
|
||||||
|
"sheet20"
|
||||||
Reference in New Issue
Block a user