-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1161 from dfinke/adding-to-import-excel
Update and improve Import-Excel for reading nultiple sheets
- Loading branch information
Showing
8 changed files
with
191 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force | ||
|
||
$xlfile = "$PSScriptRoot\yearlySales.xlsx" | ||
|
||
$result = Import-Excel $xlfile * -NotAsDictionary | ||
|
||
$result | Measure-Object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force | ||
|
||
$xlfile = "$PSScriptRoot\yearlySales.xlsx" | ||
|
||
$result = Import-Excel $xlfile * | ||
|
||
foreach ($sheet in $result.Values) { | ||
$sheet | ||
} |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
__tests__/ImportExcelTests/ImportExcelReadSheets.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#Requires -Modules Pester | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'False Positives')] | ||
param() | ||
|
||
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 -Force | ||
|
||
Describe 'Different ways to import sheets' -Tag ImportExcelReadSheets { | ||
BeforeAll { | ||
$xlFilename = "$PSScriptRoot\yearlySales.xlsx" | ||
} | ||
|
||
Context 'Test reading sheets' { | ||
It 'Should read one sheet' { | ||
$actual = Import-Excel $xlFilename | ||
|
||
$actual.Count | Should -Be 100 | ||
$actual[0].Month | Should -BeExactly "April" | ||
$actual[99].Month | Should -BeExactly "April" | ||
} | ||
|
||
It 'Should read two sheets' { | ||
$actual = Import-Excel $xlFilename march, june | ||
|
||
$actual.keys.Count | Should -Be 2 | ||
$actual["March"].Count | Should -Be 100 | ||
$actual["June"].Count | Should -Be 100 | ||
} | ||
|
||
It 'Should read all the sheets' { | ||
$actual = Import-Excel $xlFilename * | ||
|
||
$actual.keys.Count | Should -Be 12 | ||
|
||
$actual["January"].Count | Should -Be 100 | ||
$actual["February"].Count | Should -Be 100 | ||
$actual["March"].Count | Should -Be 100 | ||
$actual["April"].Count | Should -Be 100 | ||
$actual["May"].Count | Should -Be 100 | ||
$actual["June"].Count | Should -Be 100 | ||
$actual["July"].Count | Should -Be 100 | ||
$actual["August"].Count | Should -Be 100 | ||
$actual["September"].Count | Should -Be 100 | ||
$actual["October"].Count | Should -Be 100 | ||
$actual["November"].Count | Should -Be 100 | ||
$actual["December"].Count | Should -Be 100 | ||
} | ||
|
||
It 'Should throw if it cannot find the sheet' { | ||
{ Import-Excel $xlFilename april, june, notthere } | Should -Throw | ||
} | ||
|
||
It 'Should return an array not a dictionary' { | ||
$actual = Import-Excel $xlFilename april, june -NotAsDictionary | ||
|
||
$actual.Count | Should -Be 200 | ||
$group = $actual | Group-Object month -NoElement | ||
|
||
$group.Count | Should -Be 2 | ||
$group[0].Name | Should -BeExactly 'April' | ||
$group[1].Name | Should -BeExactly 'June' | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters