Compare commits

..

7 Commits

Author SHA1 Message Date
dfinke
4fa34ae257 Rename switch NotAsDictionary to Raw 2022-05-04 18:33:19 -04:00
dfinke
0b3b382c4e update 2022-05-04 18:32:27 -04:00
dfinke
415be5bca3 bump version 2022-05-04 18:32:19 -04:00
dfinke
79e5bdf8ba update 2022-05-03 17:54:21 -04:00
dfinke
b03d9b048a bump version 2022-05-03 17:54:16 -04:00
dfinke
aea90aa8d6 Fix reading multiple sheets in the xlsx where row/col count is diff 2022-05-03 17:53:58 -04:00
dfinke
d4ebc9e95d Use explicit parameter names 2022-04-30 13:17:20 -04:00
7 changed files with 34 additions and 8 deletions

View File

@@ -2,6 +2,6 @@ Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
$xlfile = "$PSScriptRoot\yearlySales.xlsx"
$result = Import-Excel $xlfile * -NotAsDictionary
$result = Import-Excel -Path $xlfile -WorksheetName * -Raw
$result | Measure-Object

View File

@@ -2,7 +2,7 @@ Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force
$xlfile = "$PSScriptRoot\yearlySales.xlsx"
$result = Import-Excel $xlfile *
$result = Import-Excel -Path $xlfile -WorksheetName *
foreach ($sheet in $result.Values) {
$sheet

View File

@@ -6,7 +6,7 @@
RootModule = 'ImportExcel.psm1'
# Version number of this module.
ModuleVersion = '7.5.0'
ModuleVersion = '7.5.2'
# ID used to uniquely identify this module
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'

View File

@@ -37,7 +37,7 @@
[ValidateNotNullOrEmpty()]
[String]$Password,
[Int[]]$ImportColumns,
[Switch]$NotAsDictionary
[Switch]$Raw
)
end {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
@@ -134,6 +134,8 @@
$xlBook = [Ordered]@{}
foreach ($sheet in $Worksheet) {
$EndRow = 0
$EndColumn = 0
$targetSheetname = $sheet.Name
$xlBook["$targetSheetname"] = @()
#region Get rows and columns
@@ -233,11 +235,11 @@
}
catch { throw "Failed importing the Excel workbook '$Path' with worksheet '$WorksheetName': $_"; return }
finally {
$EndRow = 0
$EndColumn = 0
# $EndRow = 0
# $EndColumn = 0
if ($Path) { $stream.close(); $ExcelPackage.Dispose() }
if ($NotAsDictionary) {
if ($Raw) {
foreach ($entry in $xlbook.GetEnumerator()) {
$entry.Value
}

View File

@@ -50,7 +50,7 @@ Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets {
}
It 'Should return an array not a dictionary' {
$actual = Import-Excel $xlFilename april, june -NotAsDictionary
$actual = Import-Excel $xlFilename april, june -Raw
$actual.Count | Should -Be 200
$group = $actual | Group-Object month -NoElement
@@ -59,5 +59,24 @@ Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets {
$group[0].Name | Should -BeExactly 'April'
$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
}
It "Should read multiple sheets with diff number of rows correctly and flatten it" {
$xlFilename = "$PSScriptRoot\construction.xlsx"
$actual = Import-Excel $xlFilename 2015, 2016 -Raw
$actual.Count | Should -Be 13
}
}
}

Binary file not shown.

View File

@@ -1,3 +1,8 @@
# v7.5.2
- Changed the switch `-NotAsDictionary` to `-Raw`. Works with `-Worksheetname *` reads all the sheets in the xlsx file and returns an array.
# v7.5.1
- Fixed `Import-Excel` - Reset `EndRow` and `EndColumn` in the correct place.
# v7.5.0
## Fixes