mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 13:23:29 +00:00
Fix reading multiple sheets in the xlsx where row/col count is diff
This commit is contained in:
@@ -134,6 +134,8 @@
|
|||||||
|
|
||||||
$xlBook = [Ordered]@{}
|
$xlBook = [Ordered]@{}
|
||||||
foreach ($sheet in $Worksheet) {
|
foreach ($sheet in $Worksheet) {
|
||||||
|
$EndRow = 0
|
||||||
|
$EndColumn = 0
|
||||||
$targetSheetname = $sheet.Name
|
$targetSheetname = $sheet.Name
|
||||||
$xlBook["$targetSheetname"] = @()
|
$xlBook["$targetSheetname"] = @()
|
||||||
#region Get rows and columns
|
#region Get rows and columns
|
||||||
@@ -233,8 +235,8 @@
|
|||||||
}
|
}
|
||||||
catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$WorksheetName': $_"; return }
|
catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$WorksheetName': $_"; return }
|
||||||
finally {
|
finally {
|
||||||
$EndRow = 0
|
# $EndRow = 0
|
||||||
$EndColumn = 0
|
# $EndColumn = 0
|
||||||
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
|
||||||
|
|
||||||
if ($NotAsDictionary) {
|
if ($NotAsDictionary) {
|
||||||
|
|||||||
@@ -59,5 +59,15 @@ Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets {
|
|||||||
$group[0].Name | Should -BeExactly 'April'
|
$group[0].Name | Should -BeExactly 'April'
|
||||||
$group[1].Name | Should -BeExactly 'June'
|
$group[1].Name | Should -BeExactly 'June'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should read multiple sheets with diff number of rows correctly" {
|
||||||
|
$xlFilename = "$PSScriptRoot\construction.xlsx"
|
||||||
|
|
||||||
|
$actual = Import-Excel $xlFilename 2015, 2016
|
||||||
|
$actual.keys.Count | Should -Be 2
|
||||||
|
|
||||||
|
$actual["2015"].Count | Should -Be 12
|
||||||
|
$actual["2016"].Count | Should -Be 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BIN
__tests__/ImportExcelTests/construction.xlsx
Normal file
BIN
__tests__/ImportExcelTests/construction.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user