From ecd2fbbc1f64bc0b40ad2c31e692a79cbae508fc Mon Sep 17 00:00:00 2001 From: DarkLite1 Date: Tue, 14 Feb 2017 08:28:00 +0100 Subject: [PATCH] Revert "Improved ' Get-ExcelSheetInfo '" This reverts commit d830278cbc82cb5c326b2e761302cbc7f49913eb. --- Get-ExcelSheetInfo.ps1 | 70 ++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/Get-ExcelSheetInfo.ps1 b/Get-ExcelSheetInfo.ps1 index 1e9f4eb..e60e9e5 100644 --- a/Get-ExcelSheetInfo.ps1 +++ b/Get-ExcelSheetInfo.ps1 @@ -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': $_" } } } \ No newline at end of file