mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +00:00
Merge pull request #1197 from dfinke/fix-1194-EndRow-and-EndColumn-Parameters-Ignored
Fix 1194 end row and end column parameters ignored
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
RootModule = 'ImportExcel.psm1'
|
RootModule = 'ImportExcel.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '7.5.3'
|
ModuleVersion = '7.6.0'
|
||||||
|
|
||||||
# ID used to uniquely identify this module
|
# ID used to uniquely identify this module
|
||||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||||
|
|||||||
@@ -134,8 +134,16 @@
|
|||||||
|
|
||||||
$xlBook = [Ordered]@{}
|
$xlBook = [Ordered]@{}
|
||||||
foreach ($sheet in $Worksheet) {
|
foreach ($sheet in $Worksheet) {
|
||||||
$EndRow = 0
|
if ($Worksheet.Count -gt 1 -or $Paths.Count -gt 1) {
|
||||||
$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
|
||||||
$xlBook["$targetSheetname"] = @()
|
$xlBook["$targetSheetname"] = @()
|
||||||
#region Get rows and columns
|
#region Get rows and columns
|
||||||
|
|||||||
BIN
__tests__/ImportExcelTests/DataInDiffRowCol.xlsx
Normal file
BIN
__tests__/ImportExcelTests/DataInDiffRowCol.xlsx
Normal file
Binary file not shown.
BIN
__tests__/ImportExcelTests/DataInDiffRowColMultipleSheets.xlsx
Normal file
BIN
__tests__/ImportExcelTests/DataInDiffRowColMultipleSheets.xlsx
Normal file
Binary file not shown.
@@ -0,0 +1,51 @@
|
|||||||
|
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
|
||||||
|
|
||||||
|
Describe 'Test' -Tag ImportExcelEndRowAndCols {
|
||||||
|
BeforeAll {
|
||||||
|
$script:xlFilename = "$PSScriptRoot\DataInDiffRowCol.xlsx"
|
||||||
|
}
|
||||||
|
|
||||||
|
Context 'Test reading a partial 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ Param()
|
|||||||
|
|
||||||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
|
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" {
|
It "Should find these xlsx files" {
|
||||||
Test-Path -Path $PSScriptRoot\rows05.xlsx | Should -BeTrue
|
Test-Path -Path $PSScriptRoot\rows05.xlsx | Should -BeTrue
|
||||||
Test-Path -Path $PSScriptRoot\rows10.xlsx | Should -BeTrue
|
Test-Path -Path $PSScriptRoot\rows10.xlsx | Should -BeTrue
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
# 7.6.0
|
||||||
|
- Fix -StartRow and -StartColumn being ignored.
|
||||||
|
|
||||||
# v7.5.2
|
# v7.5.2
|
||||||
- Changed the switch `-NotAsDictionary` to `-Raw`. Works with `-Worksheetname *` reads all the sheets in the xlsx file and returns an array.
|
- Changed the switch `-NotAsDictionary` to `-Raw`. Works with `-Worksheetname *` reads all the sheets in the xlsx file and returns an array.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user