From 25a970e7435fa99d6982bac090bdab2d07c29e79 Mon Sep 17 00:00:00 2001 From: dfinke Date: Thu, 7 Jan 2016 11:42:32 -0500 Subject: [PATCH] Added Get-ExcelSheetInfo --- Get-ExcelSheetInfo.ps1 | 44 ++++++++++++++++++++++++++++++++++++++++++ ImportExcel.psd1 | 2 +- ImportExcel.psm1 | 1 + README.md | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 Get-ExcelSheetInfo.ps1 diff --git a/Get-ExcelSheetInfo.ps1 b/Get-ExcelSheetInfo.ps1 new file mode 100644 index 0000000..90339bd --- /dev/null +++ b/Get-ExcelSheetInfo.ps1 @@ -0,0 +1,44 @@ +Function Get-ExcelSheetInfo { + <# + .SYNOPSIS + Get worksheet names and their indices of an Excel workbook. + + .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. + + .EXAMPLE + Get-ExcelSheetInfo .\Test.xlsx + + .NOTES + CHANGELOG + 2016/01/07 Added Created by Johan Akerstrom (https://github.com/CosmosKey) + + .LINK + https://github.com/dfinke/ImportExcel + + #> + + [CmdletBinding()] + param( + [Alias("FullName")] + [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] + $Path + ) + process { + $Path = (Resolve-Path $Path).Path + 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} + } + } + } +} \ No newline at end of file diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index fbd36c9..b9e2c7b 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. -ModuleVersion = '1.91' +ModuleVersion = '1.93' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index ac985f8..ad906ed 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -11,6 +11,7 @@ Add-Type -Path "$($PSScriptRoot)\EPPlus.dll" . $PSScriptRoot\Charting.ps1 . $PSScriptRoot\New-PSItem.ps1 . $PSScriptRoot\Pivot.ps1 +. $PSScriptRoot\Get-ExcelSheetInfo.ps1 function Import-Excel { param( diff --git a/README.md b/README.md index 69fb5d7..dc34a1d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Known Issues What's new - +### 1/7/2016 +* Added `Get-ExcelSheetInfo` - Great contribution from *Johan Åkerström* [GitHub](https://github.com/CosmosKey) [Twitter](https://twitter.com/neptune443) #### 12/26/2015