diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8eb20c8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +on: + push: + branches: + - master + - Set-up-GHA-CI/CD + + pull_request: + +jobs: + validate: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - uses: actions/checkout@v1 + - name: Run Continuous Integration + shell: pwsh + run : | + if($PSVersionTable.Platform -eq 'Win32NT') { + $null = mkdir ./ace + Invoke-Restmethod https://download.microsoft.com/download/3/5/C/35C84C36-661A-44E6-9324-8786B8DBE231/accessdatabaseengine_X64.exe -OutFile ./ace/ace.exe + Start-Process ./ace/ace.exe -Wait -ArgumentList "/quiet /passive /norestart" + } + + cd ./__tests__ + Invoke-Pester -Output Detailed \ No newline at end of file diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index ccad95c..9b4e0e0 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -6,7 +6,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '7.5.3' + ModuleVersion = '7.6.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 819fa0c..b4fe004 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -134,8 +134,16 @@ $xlBook = [Ordered]@{} foreach ($sheet in $Worksheet) { - $EndRow = 0 - $EndColumn = 0 + if ($Worksheet.Count -gt 1 -or $Paths.Count -gt 1) { + <# + 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 $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/DataInDiffRowColMultipleSheets.xlsx b/__tests__/ImportExcelTests/DataInDiffRowColMultipleSheets.xlsx new file mode 100644 index 0000000..cc3eaff Binary files /dev/null and b/__tests__/ImportExcelTests/DataInDiffRowColMultipleSheets.xlsx differ diff --git a/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 b/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 new file mode 100644 index 0000000..f9856f8 --- /dev/null +++ b/__tests__/ImportExcelTests/ImportExcelEndRowEndColumn.tests.ps1 @@ -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 + } + } +} \ 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 diff --git a/changelog.md b/changelog.md index 3e4eace..fde3f92 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +# 7.6.0 +- Fix -StartRow and -StartColumn being ignored. + # v7.5.2 - Changed the switch `-NotAsDictionary` to `-Raw`. Works with `-Worksheetname *` reads all the sheets in the xlsx file and returns an array.