From 23f1d92c1ba1ffbb0e114a77f5c98a9af2d8ae63 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 10 Jun 2023 15:27:53 -0400 Subject: [PATCH] first pass --- ImportExcel.psd1 | 3 ++- Public/Get-ExcelFileSchema.ps1 | 47 ++++++++++++++++++++++++++++++++++ changelog.md | 5 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 Public/Get-ExcelFileSchema.ps1 diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 0a1e9d9..cb27ce0 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -6,7 +6,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '7.8.4' + ModuleVersion = '7.8.5' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' @@ -54,6 +54,7 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5 'Export-Excel', 'Export-ExcelSheet', 'Get-ExcelColumnName', + 'Get-ExcelFileSchema', 'Get-ExcelFileSummary', 'Get-ExcelSheetDimensionAddress', 'Get-ExcelSheetInfo', diff --git a/Public/Get-ExcelFileSchema.ps1 b/Public/Get-ExcelFileSchema.ps1 new file mode 100644 index 0000000..ad3d1fd --- /dev/null +++ b/Public/Get-ExcelFileSchema.ps1 @@ -0,0 +1,47 @@ +function Get-ExcelFileSchema { + <# + .SYNOPSIS + Gets the schema of an Excel file. + + .DESCRIPTION + The Get-ExcelFileSchema function gets the schema of an Excel file by returning the property names of the first row of each worksheet in the file. + + .PARAMETER Path + Specifies the path to the Excel file. + + .PARAMETER Compress + Indicates whether to compress the json output. + + .OUTPUTS + Json + + .EXAMPLE + Get-ExcelFileSchema -Path .\example.xlsx + #> + + [CmdletBinding()] + param( + [Parameter(ValueFromPipelineByPropertyName, Mandatory)] + [Alias('FullName')] + $Path, + [Switch]$Compress + ) + + Begin { + $result = @() + } + + Process { + $excelFiles = Get-ExcelFileSummary $Path + + foreach ($excelFile in $excelFiles) { + $data = Import-Excel $Path -WorksheetName $excelFile.WorksheetName | Select-Object -First 1 + $names = $data[0].PSObject.Properties.name + $result += $excelFile | Add-Member -MemberType NoteProperty -Name "PropertyNames" -Value $names -PassThru + } + } + + End { + $result | ConvertTo-Json -Compress:$Compress + } +} \ No newline at end of file diff --git a/changelog.md b/changelog.md index 7fe0571..2a89d9a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +# 7.8.5 + +- Added `Get-ExcelFileSchema` to get the schema of an Excel file. + - `Get-ExcelFileSchema -Path $xlfile` + # 7.8.x Thanks to [Thomas Hofkens](https://github.com/thkn-hofa)