mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-14 23:33:18 +00:00
Revert "Improved ' Get-ExcelSheetInfo '"
This reverts commit d830278cbc.
This commit is contained in:
@@ -9,9 +9,6 @@ Function Get-ExcelSheetInfo {
|
|||||||
.PARAMETER Path
|
.PARAMETER Path
|
||||||
Specifies the path to the Excel file. This parameter is required.
|
Specifies the path to the Excel file. This parameter is required.
|
||||||
|
|
||||||
.PARAMETER Type
|
|
||||||
Specifies which information to get, the one from the workbook or the one from the sheets.
|
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Get-ExcelSheetInfo .\Test.xlsx
|
Get-ExcelSheetInfo .\Test.xlsx
|
||||||
|
|
||||||
@@ -21,34 +18,22 @@ Function Get-ExcelSheetInfo {
|
|||||||
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/dfinke/ImportExcel
|
https://github.com/dfinke/ImportExcel
|
||||||
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
Param (
|
param(
|
||||||
[Alias("FullName")]
|
[Alias("FullName")]
|
||||||
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)]
|
[Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)]
|
||||||
[String]$Path,
|
$Path
|
||||||
[ValidateSet('Sheets', 'Workbook')]
|
|
||||||
[String]$Type = 'Workbook'
|
|
||||||
)
|
)
|
||||||
|
process {
|
||||||
Process {
|
|
||||||
Try {
|
|
||||||
$Path = (Resolve-Path $Path).ProviderPath
|
$Path = (Resolve-Path $Path).ProviderPath
|
||||||
|
write-debug "target excel file $Path"
|
||||||
Write-Debug "target excel file $Path"
|
|
||||||
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
|
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
|
||||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
|
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
|
||||||
$workbook = $xl.Workbook
|
$workbook = $xl.Workbook
|
||||||
|
if($workbook -and $workbook.Worksheets) {
|
||||||
Switch ($Type) {
|
|
||||||
'Workbook' {
|
|
||||||
if ($workbook) {
|
|
||||||
$workbook.Properties
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'Sheets' {
|
|
||||||
if ($workbook -and $workbook.Worksheets) {
|
|
||||||
$workbook.Worksheets |
|
$workbook.Worksheets |
|
||||||
Select-Object -Property name,index,hidden,@{
|
Select-Object -Property name,index,hidden,@{
|
||||||
Label = "Path"
|
Label = "Path"
|
||||||
@@ -56,13 +41,4 @@ Function Get-ExcelSheetInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Default {
|
|
||||||
Write-Error 'Unrecogrnized type'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Catch {
|
|
||||||
throw "Failed retrieving Excel sheet information for '$Path': $_"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user