diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index c6c22be..e6934d7 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -6,7 +6,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '7.4.2' + ModuleVersion = '7.5.0' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/Public/Import-Excel.ps1 b/Public/Import-Excel.ps1 index adadc82..49982cb 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -226,6 +226,8 @@ } catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$WorksheetName': $_"; return } finally { + $EndRow = 0 + $EndColumn = 0 if ($Path) { $stream.close(); $ExcelPackage.Dispose() } } } diff --git a/__tests__/ImportExcelHeaderName.tests.ps1 b/__tests__/ImportExcelHeaderName.tests.ps1 index 41944df..90ef05e 100644 --- a/__tests__/ImportExcelHeaderName.tests.ps1 +++ b/__tests__/ImportExcelHeaderName.tests.ps1 @@ -230,6 +230,7 @@ Describe "Import-Excel on a sheet with no headings" { $actual.Count | Should -Be 1 + Remove-Item $xlfile # Looks like -DataOnly does not handle empty columns # $actual[0].FirstName | Should -BeExactly 'Jean-Claude' # $actual[0].SecondName | Should -BeExactly 'Vandamme' diff --git a/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 b/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 new file mode 100644 index 0000000..b8631a3 --- /dev/null +++ b/__tests__/ImportExcelTests/ReadMultipleXLSXFiles.tests.ps1 @@ -0,0 +1,57 @@ +[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'False Positives')] +Param() + +Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force + +Describe "Test reading multiple XLSX files of differernt 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 + } + + It "Should find two xlsx files" { + (Get-ChildItem $PSScriptRoot\row*xlsx).Count | Should -Be 2 + } + + It "Should get 5 rows" { + (Import-Excel $PSScriptRoot\rows05.xlsx).Count | Should -Be 5 + } + + It "Should get 10 rows" { + (Import-Excel $PSScriptRoot\rows10.xlsx).Count | Should -Be 10 + } + + It "Should get 15 rows" { + $actual = Get-ChildItem $PSScriptRoot\row*xlsx | Import-Excel + + $actual.Count | Should -Be 15 + } + + It "Should get 4 property names" { + $actual = Get-ChildItem $PSScriptRoot\row*xlsx | Import-Excel + + $names = $actual[0].psobject.properties.name + $names.Count | Should -Be 4 + + $names[0] | Should -BeExactly "Region" + $names[1] | Should -BeExactly "State" + $names[2] | Should -BeExactly "Units" + $names[3] | Should -BeExactly "Price" + } + + It "Should have the correct data" { + $actual = Get-ChildItem $PSScriptRoot\row*xlsx | Import-Excel + + # rows05.xlsx + $actual[0].Region | Should -BeExactly "South" + $actual[0].Price | Should -Be 181.52 + $actual[4].Region | Should -BeExactly "West" + $actual[4].Price | Should -Be 216.56 + + # rows10.xlsx + $actual[5].Region | Should -BeExactly "South" + $actual[5].Price | Should -Be 199.85 + $actual[14].Region | Should -BeExactly "East" + $actual[14].Price | Should -Be 965.25 + } +} \ No newline at end of file diff --git a/__tests__/ImportExcelTests/rows05.xlsx b/__tests__/ImportExcelTests/rows05.xlsx new file mode 100644 index 0000000..3f54f30 Binary files /dev/null and b/__tests__/ImportExcelTests/rows05.xlsx differ diff --git a/__tests__/ImportExcelTests/rows10.xlsx b/__tests__/ImportExcelTests/rows10.xlsx new file mode 100644 index 0000000..0ca23b9 Binary files /dev/null and b/__tests__/ImportExcelTests/rows10.xlsx differ diff --git a/__tests__/testImportExcelSparse.xlsx b/__tests__/testImportExcelSparse.xlsx deleted file mode 100644 index 099cbf7..0000000 Binary files a/__tests__/testImportExcelSparse.xlsx and /dev/null differ diff --git a/changelog.md b/changelog.md index c27429a..0381954 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +# v7.5.0 + +## Fixes + +- Importing multiple files with Import-Excel by pipeline uses only the first file for the row count https://github.com/dfinke/ImportExcel/issues/1172 + # v7.4.2 - Thank you [James Mueller](https://github.com/jamesmmueller) Updated `ConvertFrom-ExcelToSQLInsert` to handle single quotes in the SQL statement.