mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 13:23:29 +00:00
Merged ValidateSet for Encoding and Extension
This commit is contained in:
40
Export-ExcelSheet.ps1
Normal file
40
Export-ExcelSheet.ps1
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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()
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
RootModule = 'ImportExcel.psm1'
|
RootModule = 'ImportExcel.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '1.81'
|
ModuleVersion = '1.82'
|
||||||
|
|
||||||
# ID used to uniquely identify this module
|
# ID used to uniquely identify this module
|
||||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll"
|
|||||||
|
|
||||||
. $PSScriptRoot\Export-Excel.ps1
|
. $PSScriptRoot\Export-Excel.ps1
|
||||||
. $PSScriptRoot\New-ConditionalFormattingIconSet.ps1
|
. $PSScriptRoot\New-ConditionalFormattingIconSet.ps1
|
||||||
|
. $PSScriptRoot\Export-ExcelSheet.ps1
|
||||||
|
|
||||||
function Import-Excel {
|
function Import-Excel {
|
||||||
param(
|
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 {
|
function Add-WorkSheet {
|
||||||
param(
|
param(
|
||||||
#TODO Use parametersets to allow a workbook to be passed instead of a package
|
#TODO Use parametersets to allow a workbook to be passed instead of a package
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
param([string]$InstallDirectory)
|
param([string]$InstallDirectory)
|
||||||
|
|
||||||
$fileList = echo EPPlus.dll ImportExcel.psd1 ImportExcel.psm1 Export-Excel.ps1 New-ConditionalFormattingIconSet.ps1
|
$fileList = echo EPPlus.dll ImportExcel.psd1 ImportExcel.psm1 Export-Excel.ps1 New-ConditionalFormattingIconSet.ps1 Export-ExcelSheet.ps1
|
||||||
|
|
||||||
|
|
||||||
if ('' -eq $InstallDirectory)
|
if ('' -eq $InstallDirectory)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ $p = @{
|
|||||||
NuGetApiKey = $NuGetApiKey
|
NuGetApiKey = $NuGetApiKey
|
||||||
LicenseUri = "https://github.com/dfinke/ImportExcel/blob/master/LICENSE.txt"
|
LicenseUri = "https://github.com/dfinke/ImportExcel/blob/master/LICENSE.txt"
|
||||||
Tag = "Excel","EPPlus","Export","Import"
|
Tag = "Excel","EPPlus","Export","Import"
|
||||||
ReleaseNote = "Can now handle data that is _not_ an object"
|
ReleaseNote = "ValidateSet for Encoding and Extension"
|
||||||
ProjectUri = "https://github.com/dfinke/ImportExcel"
|
ProjectUri = "https://github.com/dfinke/ImportExcel"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ Know Issues
|
|||||||
|
|
||||||
What's new
|
What's new
|
||||||
-
|
-
|
||||||
|
|
||||||
|
#### 10/1/2015
|
||||||
|
|
||||||
|
Merged ValidateSet for Encoding and Extension. Thank you [Irwin Strachan](https://github.com/irwins).
|
||||||
|
|
||||||
#### 9/30/2015
|
#### 9/30/2015
|
||||||
|
|
||||||
Export-Excel can now handle data that is **not** an object
|
Export-Excel can now handle data that is **not** an object
|
||||||
|
|||||||
Reference in New Issue
Block a user