mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Add switch to not return data as a dictionary
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
[string[]]$AsDate,
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$Password,
|
||||
[Int[]]$ImportColumns
|
||||
[Int[]]$ImportColumns,
|
||||
[Switch]$NoHashtable
|
||||
)
|
||||
end {
|
||||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
@@ -234,7 +235,12 @@
|
||||
finally {
|
||||
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
||||
|
||||
if ($Worksheet.Count -eq 1) {
|
||||
if ($NoHashtable) {
|
||||
foreach ($entry in $xlbook.GetEnumerator()) {
|
||||
$entry.Value
|
||||
}
|
||||
}
|
||||
elseif ($Worksheet.Count -eq 1) {
|
||||
$xlBook["$targetSheetname"]
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Requires -Modules Pester
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'False Positives')]
|
||||
param()
|
||||
|
||||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
|
||||
@@ -48,5 +48,16 @@ Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets {
|
||||
It 'Should throw if it cannot find the sheet' {
|
||||
{ Import-Excel $xlFilename april, june, notthere } | Should -Throw
|
||||
}
|
||||
|
||||
It 'Should return an array not a dictionary' {
|
||||
$actual = Import-Excel $xlFilename april, june -NoHashtable
|
||||
|
||||
$actual.Count | Should -Be 200
|
||||
$group = $actual | Group-Object month -NoElement
|
||||
|
||||
$group.Count | Should -Be 2
|
||||
$group[0].Name | Should -BeExactly 'April'
|
||||
$group[1].Name | Should -BeExactly 'June'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user