Fix bug #1172
This commit is contained in:
Doug Finke
2022-04-30 07:10:57 -04:00
committed by GitHub
8 changed files with 67 additions and 1 deletions

View File

@@ -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'

View File

@@ -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() }
}
}

View File

@@ -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'

View File

@@ -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
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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.