first pass

This commit is contained in:
dfinke
2023-06-10 15:27:53 -04:00
parent ab4d03c984
commit 23f1d92c1b
3 changed files with 54 additions and 1 deletions

View File

@@ -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',

View File

@@ -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
}
}

View File

@@ -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)