Add additional tests

This commit is contained in:
dfinke
2022-06-12 10:42:16 -04:00
parent ef35c4fca8
commit ab56ae4409
4 changed files with 26 additions and 6 deletions

View File

@@ -135,8 +135,13 @@
$xlBook = [Ordered]@{} $xlBook = [Ordered]@{}
foreach ($sheet in $Worksheet) { foreach ($sheet in $Worksheet) {
if ($Worksheet.Count -gt 1 -or $Paths.Count -gt 1) { if ($Worksheet.Count -gt 1 -or $Paths.Count -gt 1) {
$EndRow = 0 <#
$EndColumn = 0 Needed under these conditions to handle sheets of different number of Row/Col
- When reading more than one xlsx file
- When reading more than one worksheet in the same file
#>
$EndRow = $null
$EndColumn = $null
} }
$targetSheetname = $sheet.Name $targetSheetname = $sheet.Name

View File

@@ -5,11 +5,11 @@ Describe 'Test' -Tag ImportExcelEndRowAndCols {
$script:xlFilename = "$PSScriptRoot\DataInDiffRowCol.xlsx" $script:xlFilename = "$PSScriptRoot\DataInDiffRowCol.xlsx"
} }
Context 'Test reading a patial sheet' { Context 'Test reading a partial sheet' {
It 'Should read 2 rows and first 3 columns' { It 'Should read 2 rows and first 3 columns' {
$actual = Import-Excel $xlFilename -StartRow 5 -EndRow 7 -StartColumn 3 -EndColumn 5 $actual = Import-Excel $xlFilename -StartRow 5 -EndRow 7 -StartColumn 3 -EndColumn 5
$actual | out-host # $actual | out-host
$actual.Count | Should -Be 2 $actual.Count | Should -Be 2
$colNames = $actual[0].psobject.properties.Name $colNames = $actual[0].psobject.properties.Name
@@ -23,7 +23,7 @@ Describe 'Test' -Tag ImportExcelEndRowAndCols {
It 'Should read second 2 rows and last 2 columns' { It 'Should read second 2 rows and last 2 columns' {
$actual = Import-Excel $xlFilename -StartRow 8 -EndRow 9 -StartColumn 5 -EndColumn 6 -HeaderName 'Units', 'Price' $actual = Import-Excel $xlFilename -StartRow 8 -EndRow 9 -StartColumn 5 -EndColumn 6 -HeaderName 'Units', 'Price'
$actual | out-host # $actual | out-host
$actual.Count | Should -Be 2 $actual.Count | Should -Be 2
$colNames = $actual[0].psobject.properties.Name $colNames = $actual[0].psobject.properties.Name
@@ -33,4 +33,19 @@ Describe 'Test' -Tag ImportExcelEndRowAndCols {
$colNames[1] | Should -Be 'Price' $colNames[1] | Should -Be 'Price'
} }
} }
Context 'Test reading multiple sheets with data in differnt rows and columns' {
It 'Should read 2 sheets same StartRow different dimensions' {
$xlFilename = "$PSScriptRoot\DataInDiffRowColMultipleSheets.xlsx"
$actual = Import-Excel $xlFilename -StartRow 5 -WorksheetName *
$actual.Keys.Count | Should -Be 2
$actual.Contains('Sheet1') | Should -BeTrue
$actual.Contains('Sheet2') | Should -BeTrue
$actual['Sheet1'].Count | Should -Be 9
$actual['Sheet2'].Count | Should -Be 12
}
}
} }

View File

@@ -23,7 +23,7 @@ Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets {
$actual.keys.Count | Should -Be 2 $actual.keys.Count | Should -Be 2
$actual["March"].Count | Should -Be 100 $actual["March"].Count | Should -Be 100
$actual["June"].Count | Should -Be 100 $actual["June"].Count | Should -Be 100x`
} }
It 'Should read all the sheets' { It 'Should read all the sheets' {