diff --git a/Public/Import-Excel.ps1 b/Public/Import-Excel.ps1 index 819fa0c..f95bc25 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -134,8 +134,11 @@ $xlBook = [Ordered]@{} foreach ($sheet in $Worksheet) { - $EndRow = 0 - $EndColumn = 0 + if ($Worksheet.Count -gt 1 -or $Paths.Count -gt 1) { + $EndRow = 0 + $EndColumn = 0 + } + $targetSheetname = $sheet.Name $xlBook["$targetSheetname"] = @() #region Get rows and columns diff --git a/__tests__/ImportExcelTests/DataInDiffRowCol.xlsx b/__tests__/ImportExcelTests/DataInDiffRowCol.xlsx new file mode 100644 index 0000000..f09b5b7 Binary files /dev/null and b/__tests__/ImportExcelTests/DataInDiffRowCol.xlsx differ diff --git a/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 b/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 new file mode 100644 index 0000000..e66a301 --- /dev/null +++ b/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 @@ -0,0 +1,36 @@ +Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force + +Describe 'Test' -Tag ImportExcelEndRowAndCols { + BeforeAll { + $script:xlFilename = "$PSScriptRoot\DataInDiffRowCol.xlsx" + } + + Context 'Test reading a patial sheet' { + It 'Should read 2 rows and first 3 columns' { + $actual = Import-Excel $xlFilename -StartRow 5 -EndRow 7 -StartColumn 3 -EndColumn 5 + + $actual | out-host + $actual.Count | Should -Be 2 + + $colNames = $actual[0].psobject.properties.Name + $colNames.Count | Should -Be 3 + + $colNames[0] | Should -Be 'Region' + $colNames[1] | Should -Be 'State' + $colNames[2] | Should -Be 'Units' + } + + 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 | out-host + $actual.Count | Should -Be 2 + + $colNames = $actual[0].psobject.properties.Name + $colNames.Count | Should -Be 2 + + $colNames[0] | Should -Be 'Units' + $colNames[1] | Should -Be 'Price' + } + } +} \ No newline at end of file diff --git a/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 b/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 index b8631a3..27ff841 100644 --- a/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 +++ b/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 @@ -3,7 +3,7 @@ Param() Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force -Describe "Test reading multiple XLSX files of differernt row count" -Tag ReadMultipleXLSX { +Describe "Test reading multiple XLSX files of different row count" -Tag ReadMultipleXLSX { It "Should find these xlsx files" { Test-Path -Path $PSScriptRoot\rows05.xlsx | Should -BeTrue Test-Path -Path $PSScriptRoot\rows10.xlsx | Should -BeTrue