mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Revert "Improved ' Get-ExcelSheetInfo '"
This reverts commit d830278cbc.
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
Function Get-ExcelSheetInfo {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Get worksheet names and their indices of an Excel workbook.
|
||||
|
||||
.DESCRIPTION
|
||||
|
||||
.DESCRIPTION
|
||||
The Get-ExcelSheetInfo cmdlet gets worksheet names and their indices of an Excel workbook.
|
||||
|
||||
|
||||
.PARAMETER Path
|
||||
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
|
||||
Get-ExcelSheetInfo .\Test.xlsx
|
||||
Get-ExcelSheetInfo .\Test.xlsx
|
||||
|
||||
.NOTES
|
||||
CHANGELOG
|
||||
@@ -21,48 +18,27 @@ Function Get-ExcelSheetInfo {
|
||||
|
||||
.LINK
|
||||
https://github.com/dfinke/ImportExcel
|
||||
#>
|
||||
|
||||
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
Param (
|
||||
param(
|
||||
[Alias("FullName")]
|
||||
[Parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)]
|
||||
[String]$Path,
|
||||
[ValidateSet('Sheets', 'Workbook')]
|
||||
[String]$Type = 'Workbook'
|
||||
[Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)]
|
||||
$Path
|
||||
)
|
||||
|
||||
Process {
|
||||
Try {
|
||||
$Path = (Resolve-Path $Path).ProviderPath
|
||||
|
||||
Write-Debug "target excel file $Path"
|
||||
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
|
||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
|
||||
$workbook = $xl.Workbook
|
||||
|
||||
Switch ($Type) {
|
||||
'Workbook' {
|
||||
if ($workbook) {
|
||||
$workbook.Properties
|
||||
}
|
||||
process {
|
||||
$Path = (Resolve-Path $Path).ProviderPath
|
||||
write-debug "target excel file $Path"
|
||||
$stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,"Open","Read","ReadWrite"
|
||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $stream
|
||||
$workbook = $xl.Workbook
|
||||
if($workbook -and $workbook.Worksheets) {
|
||||
$workbook.Worksheets |
|
||||
Select-Object -Property name,index,hidden,@{
|
||||
Label = "Path"
|
||||
Expression = {$Path}
|
||||
}
|
||||
'Sheets' {
|
||||
if ($workbook -and $workbook.Worksheets) {
|
||||
$workbook.Worksheets |
|
||||
Select-Object -Property name,index,hidden,@{
|
||||
Label = "Path"
|
||||
Expression = {$Path}
|
||||
}
|
||||
}
|
||||
}
|
||||
Default {
|
||||
Write-Error 'Unrecogrnized type'
|
||||
}
|
||||
}
|
||||
}
|
||||
Catch {
|
||||
throw "Failed retrieving Excel sheet information for '$Path': $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user