mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 21:33:16 +00:00
Add switch to not return data as a dictionary
This commit is contained in:
@@ -36,7 +36,8 @@
|
|||||||
[string[]]$AsDate,
|
[string[]]$AsDate,
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[String]$Password,
|
[String]$Password,
|
||||||
[Int[]]$ImportColumns
|
[Int[]]$ImportColumns,
|
||||||
|
[Switch]$NoHashtable
|
||||||
)
|
)
|
||||||
end {
|
end {
|
||||||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||||
@@ -234,7 +235,12 @@
|
|||||||
finally {
|
finally {
|
||||||
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
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"]
|
$xlBook["$targetSheetname"]
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#Requires -Modules Pester
|
#Requires -Modules Pester
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'False Positives')]
|
||||||
param()
|
param()
|
||||||
|
|
||||||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
|
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' {
|
It 'Should throw if it cannot find the sheet' {
|
||||||
{ Import-Excel $xlFilename april, june, notthere } | Should -Throw
|
{ 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