From ad35d398500f733d4ae60aa05a7c3273335cfded Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 13 Feb 2019 16:23:37 -0500 Subject: [PATCH 1/8] Removed unneed tests --- ImportExcel.Tests.ps1 | 2084 ------------------------------------ Old_Export-Excel.Tests.ps1 | 94 -- 2 files changed, 2178 deletions(-) delete mode 100644 ImportExcel.Tests.ps1 delete mode 100644 Old_Export-Excel.Tests.ps1 diff --git a/ImportExcel.Tests.ps1 b/ImportExcel.Tests.ps1 deleted file mode 100644 index faacee7..0000000 --- a/ImportExcel.Tests.ps1 +++ /dev/null @@ -1,2084 +0,0 @@ -#Requires -Modules Pester -#Requires -Modules Assert - -$here = Split-Path -Parent $MyInvocation.MyCommand.Path -$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.' - -Import-Module $here -Force - -$WarningPreference = 'SilentlyContinue' -# $WarningPreference = 'Continue' -$ProgressPreference = 'SilentlyContinue' - -$Path = 'Test.xlsx' -#<# -Context 'input' { - in $TestDrive { - Describe 'parameters' { - BeforeEach { - Remove-Item ./* -Force - } - Context 'mandatory in sets' { - it 'Path' { - (Get-Command Import-Excel).Parameters['Path'].Attributes.Mandatory | Should be $true - } - it 'HeaderName' { - (Get-Command Import-Excel).Parameters['HeaderName'].Attributes.Mandatory | Should be $true - } - it 'NoHeader' { - (Get-Command Import-Excel).Parameters['NoHeader'].Attributes.Mandatory | Should be $true - } - } - Context 'optional' { - it 'DataOnly' { - (Get-Command Import-Excel).Parameters['DataOnly'].Attributes.Mandatory | Should be $false - } - it 'StartRow' { - (Get-Command Import-Excel).Parameters['StartRow'].Attributes.Mandatory | Should be $false - } - it 'WorksheetName' { - (Get-Command Import-Excel).Parameters['WorksheetName'].Attributes.Mandatory | Should be $false - } - it 'Password' { - (Get-Command Import-Excel).Parameters['Password'].Attributes.Mandatory | Should be $false - } - } - Context 'aliases' { - it 'Path' { - (Get-Command Import-Excel).Parameters['Path'].Attributes.AliasNames | Should be 'FullName' - } - it 'WorksheetName' { - (Get-Command Import-Excel).Parameters['WorksheetName'].Attributes.AliasNames | Should be 'Sheet' - } - it 'StartRow' { - (Get-Command Import-Excel).Parameters['StartRow'].Attributes.AliasNames | Should be @('HeaderRow','TopRow') - } - } - Context 'illegal' { - it 'NoHeader combined with HeaderName' { - 'Kiwi'| Export-Excel -Path $Path -WorkSheetname Fruit - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName A -NoHeader} | Should Throw 'Parameter set cannot be resolved' - } - it 'HeaderName with blanks' { - 'Kiwi'| Export-Excel -Path $Path -WorkSheetname Fruit - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName A, $null, C} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName $null, C} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName $null} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName A, '', C} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName '', C} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - {Import-Excel -Path $Path -WorksheetName Fruit -HeaderName ''} | Should Throw "Cannot bind argument to parameter 'HeaderName'" - } - it 'Path does not exist' { - {Import-Excel -Path D:\DontExist -WorksheetName Fruit} | Should Throw "Cannot validate argument on parameter 'Path'" - } - it 'Path exists but does not have extension .xlsx or .xls' { - 'Kiwi' | Out-File NotAnExcelFile.txt - Test-Path -Path NotAnExcelFile.txt -PathType Leaf | Should be $true - {Import-Excel -Path NotAnExcelFile.txt -WorksheetName Fruit} | Should Throw "Cannot validate argument on parameter 'Path'" - } - it 'WorksheetName left blank' { - 'Kiwi'| Export-Excel -Path $Path -WorkSheetname Fruit - {Import-Excel -Path $Path -WorksheetName $null} | Should Throw "Cannot validate argument on parameter 'WorksheetName'. The argument is null or empty" - {Import-Excel -Path $Path -WorksheetName ''} | Should Throw "Cannot validate argument on parameter 'WorksheetName'. The argument is null or empty" - } - it 'Password left blank' { - 'Kiwi'| Export-Excel -Path $Path -WorkSheetname Fruit - {Import-Excel -Path $Path -WorksheetName Fruit -Password $null} | Should Throw "Cannot validate argument on parameter 'Password'. The argument is null or empty" - {Import-Excel -Path $Path -WorksheetName Fruit -Password ''} | Should Throw "Cannot validate argument on parameter 'Password'. The argument is null or empty" - } - } - Context 'omit parameter name' { - it 'Path' { - [PSCustomObject]@{ - Number = 1 - } | Export-Excel -Path $Path -WorkSheetname Test - - $ExpectedResult = [PSCustomObject]@{ - 'Number' = '1' - } - - $Result = Import-Excel $Path - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Path and WorksheetName' { - [PSCustomObject]@{ - Number = 1 - } | Export-Excel -Path $Path -WorkSheetname Test - - $ExpectedResult = [PSCustomObject]@{ - 'Number' = '1' - } - - $Result = Import-Excel $Path Test - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Path and WorksheetName with NoHeader' { - 'Kiwi' | Export-Excel -Path $Path -WorkSheetname Fruit - - $ExpectedResult = [PSCustomObject]@{ - P1 = 'Kiwi' - } - - $Result = Import-Excel $Path Fruit -NoHeader - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Path and WorksheetName with HeaderName' { - 'Kiwi' | Export-Excel -Path $Path -WorkSheetname Fruit - - $ExpectedResult = [PSCustomObject]@{ - Fruits = 'Kiwi' - } - - $Result = Import-Excel $Path Fruit -HeaderName Fruits - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - } - } - Describe 'worksheet' { - #region Create test file - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Excel | Add-WorkSheet -WorkSheetname Test - $Excel.Save() - $Excel.Dispose() - #endregion - - it 'not found' { - {Import-Excel -Path $Path -WorksheetName NotExisting} | Should Throw 'not found' - } - it 'empty' { - Import-Excel -Path $Path -WorksheetName Test -NoHeader | Should BeNullOrEmpty - } - it 'select first worksheet by default' { - Remove-Item ./* -Force - #region Create test file - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - - - # ---------------------------------------------- - # | A B C | - # |1 First Name Address | - # |2 Chuck Norris California | - # |3 Jean-Claude Vandamme Brussels | - # ---------------------------------------------- - - # Row, Column - $WorksheetActors = $Excel | Add-WorkSheet -WorkSheetname Actors - $WorksheetActors.Cells[1, 1].Value = 'First Name' - $WorksheetActors.Cells[1, 3].Value = 'Address' - $WorksheetActors.Cells[2, 1].Value = 'Chuck' - $WorksheetActors.Cells[2, 2].Value = 'Norris' - $WorksheetActors.Cells[2, 3].Value = 'California' - $WorksheetActors.Cells[3, 1].Value = 'Jean-Claude' - $WorksheetActors.Cells[3, 2].Value = 'Vandamme' - $WorksheetActors.Cells[3, 3].Value = 'Brussels' - - # --------------------------------------------------------------------- - # | A B C D E | - # |1 Movie name Year Rating Genre | - # |2 The Bodyguard 1992 9 Thriller | - # |3 The Matrix 1999 8 Sci-Fi | - # |4 | - # |5 Skyfall 2012 9 Thriller | - # --------------------------------------------------------------------- - - # Row, Column - $WorksheetMovies = $Excel | Add-WorkSheet -WorkSheetname Movies - $WorksheetMovies.Cells[1, 1].Value = 'Movie name' - $WorksheetMovies.Cells[1, 2].Value = 'Year' - $WorksheetMovies.Cells[1, 3].Value = 'Rating' - $WorksheetMovies.Cells[1, 5].Value = 'Genre' - $WorksheetMovies.Cells[2, 1].Value = 'The Bodyguard' - $WorksheetMovies.Cells[2, 2].Value = '1982' - $WorksheetMovies.Cells[2, 3].Value = '9' - $WorksheetMovies.Cells[2, 5].Value = 'Thriller' - $WorksheetMovies.Cells[3, 1].Value = 'The Matrix' - $WorksheetMovies.Cells[3, 2].Value = '1999' - $WorksheetMovies.Cells[3, 3].Value = '8' - $WorksheetMovies.Cells[3, 5].Value = 'Sci-Fi' - $WorksheetMovies.Cells[5, 1].Value = 'Skyfall' - $WorksheetMovies.Cells[5, 2].Value = '2012' - $WorksheetMovies.Cells[5, 3].Value = '9' - $WorksheetMovies.Cells[5, 5].Value = 'Thriller' - - $Excel.Save() - $Excel.Dispose() - #endregion - - $ExpectedResult = @( - [PSCustomObject]@{ - 'First Name' = 'Chuck' - 'Address' = 'California' - } - [PSCustomObject]@{ - 'First Name' = 'Jean-Claude' - 'Address' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Remove-Item ./* -Force - - #region Create test file - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - - # --------------------------------------------------------------------- - # | A B C D E | - # |1 Movie name Year Rating Genre | - # |2 The Bodyguard 1992 9 Thriller | - # |3 The Matrix 1999 8 Sci-Fi | - # |4 | - # |5 Skyfall 2012 9 Thriller | - # --------------------------------------------------------------------- - - # Row, Column - $WorksheetMovies = $Excel | Add-WorkSheet -WorkSheetname Movies - $WorksheetMovies.Cells[1, 1].Value = 'Movie name' - $WorksheetMovies.Cells[1, 2].Value = 'Year' - $WorksheetMovies.Cells[1, 3].Value = 'Rating' - $WorksheetMovies.Cells[1, 5].Value = 'Genre' - $WorksheetMovies.Cells[2, 1].Value = 'The Bodyguard' - $WorksheetMovies.Cells[2, 2].Value = '1982' - $WorksheetMovies.Cells[2, 3].Value = '9' - $WorksheetMovies.Cells[2, 5].Value = 'Thriller' - $WorksheetMovies.Cells[3, 1].Value = 'The Matrix' - $WorksheetMovies.Cells[3, 2].Value = '1999' - $WorksheetMovies.Cells[3, 3].Value = '8' - $WorksheetMovies.Cells[3, 5].Value = 'Sci-Fi' - $WorksheetMovies.Cells[5, 1].Value = 'Skyfall' - $WorksheetMovies.Cells[5, 2].Value = '2012' - $WorksheetMovies.Cells[5, 3].Value = '9' - $WorksheetMovies.Cells[5, 5].Value = 'Thriller' - - # ---------------------------------------------- - # | A B C | - # |1 First Name Address | - # |2 Chuck Norris California | - # |3 Jean-Claude Vandamme Brussels | - # ---------------------------------------------- - - # Row, Column - $WorksheetActors = $Excel | Add-WorkSheet -WorkSheetname Actors - $WorksheetActors.Cells[1, 1].Value = 'First Name' - $WorksheetActors.Cells[1, 3].Value = 'Address' - $WorksheetActors.Cells[2, 1].Value = 'Chuck' - $WorksheetActors.Cells[2, 2].Value = 'Norris' - $WorksheetActors.Cells[2, 3].Value = 'California' - $WorksheetActors.Cells[3, 1].Value = 'Jean-Claude' - $WorksheetActors.Cells[3, 2].Value = 'Vandamme' - $WorksheetActors.Cells[3, 3].Value = 'Brussels' - - $Excel.Save() - $Excel.Dispose() - #endregion - - $ExpectedResult = @( - [PSCustomObject]@{ - 'Movie name' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'Movie name' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'Movie name' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'Movie name' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - } - } -} - -Context 'output' { - in $TestDrive { - Describe 'missing column header' { - - #region Create test file - - # ---------------------------------------------- - # | A B C | - # |1 First Name Address | - # |2 Chuck Norris California | - # |3 Jean-Claude Vandamme Brussels | - # ---------------------------------------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - - # Row, Column - $Worksheet.Cells[1, 1].Value = 'First Name' - $Worksheet.Cells[1, 3].Value = 'Address' - $Worksheet.Cells[2, 1].Value = 'Chuck' - $Worksheet.Cells[2, 2].Value = 'Norris' - $Worksheet.Cells[2, 3].Value = 'California' - $Worksheet.Cells[3, 1].Value = 'Jean-Claude' - $Worksheet.Cells[3, 2].Value = 'Vandamme' - $Worksheet.Cells[3, 3].Value = 'Brussels' - - $Excel.Save() - $Excel.Dispose() - #endregion - - it 'Default' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'First Name' = 'Chuck' - 'Address' = 'California' - } - [PSCustomObject]@{ - 'First Name' = 'Jean-Claude' - 'Address' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default and StartRow' { - $ExpectedResult = [PSCustomObject]@{ - 'Chuck' = 'Jean-Claude' - 'Norris' = 'Vandamme' - 'California' = 'Brussels' - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -StartRow 4 | Should BeNullOrEmpty - } - it 'Default and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'First Name' = 'Chuck' - 'Address' = 'California' - } - [PSCustomObject]@{ - 'First Name' = 'Jean-Claude' - 'Address' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default, DataOnly and StartRow' { - $ExpectedResult = [PSCustomObject]@{ - 'Chuck' = 'Jean-Claude' - 'Norris' = 'Vandamme' - 'California' = 'Brussels' - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 4 | Should BeNullOrEmpty - } - it 'NoHeader' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'First Name' - 'P2' = $null - 'P3' = 'Address' - } - [PSCustomObject]@{ - 'P1' = 'Chuck' - 'P2' = 'Norris' - 'P3' = 'California' - } - [PSCustomObject]@{ - 'P1' = 'Jean-Claude' - 'P2' = 'Vandamme' - 'P3' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Chuck' - 'P2' = 'Norris' - 'P3' = 'California' - } - [PSCustomObject]@{ - 'P1' = 'Jean-Claude' - 'P2' = 'Vandamme' - 'P3' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 4 | Should BeNullOrEmpty - } - it 'NoHeader and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'First Name' - 'P2' = $null - 'P3' = 'Address' - } - [PSCustomObject]@{ - 'P1' = 'Chuck' - 'P2' = 'Norris' - 'P3' = 'California' - } - [PSCustomObject]@{ - 'P1' = 'Jean-Claude' - 'P2' = 'Vandamme' - 'P3' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Chuck' - 'P2' = 'Norris' - 'P3' = 'California' - } - [PSCustomObject]@{ - 'P1' = 'Jean-Claude' - 'P2' = 'Vandamme' - 'P3' = 'Brussels' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 4 | Should BeNullOrEmpty - } - it 'HeaderName' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'First Name' - 'SecondName' = $null - 'City' = 'Address' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'First Name' - 'SecondName' = $null - 'City' = 'Address' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country -StartRow 4 | Should BeNullOrEmpty - } - it 'HeaderName and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'First Name' - 'SecondName' = $null - 'City' = 'Address' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'First Name' - 'SecondName' = $null - 'City' = 'Address' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'FirstName' = 'Chuck' - 'SecondName' = 'Norris' - 'City' = 'California' - 'Rating' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'FirstName' = 'Jean-Claude' - 'SecondName' = 'Vandamme' - 'City' = 'Brussels' - 'Rating' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -HeaderName FirstName, SecondName, City, Rating, Country -DataOnly -StartRow 4 | Should BeNullOrEmpty - } - } - Describe 'blank rows and columns' { - - #region Create test file - - # --------------------------------------------------------------------- - # | A B C D E | - # |1 Movie name Year Rating Genre | - # |2 The Bodyguard 1992 9 Thriller | - # |3 The Matrix 1999 8 Sci-Fi | - # |4 | - # |5 Skyfall 2012 9 Thriller | - # --------------------------------------------------------------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - - # Row, Column - $Worksheet.Cells[1, 1].Value = 'Movie name' - $Worksheet.Cells[1, 2].Value = 'Year' - $Worksheet.Cells[1, 3].Value = 'Rating' - $Worksheet.Cells[1, 5].Value = 'Genre' - $Worksheet.Cells[2, 1].Value = 'The Bodyguard' - $Worksheet.Cells[2, 2].Value = '1982' - $Worksheet.Cells[2, 3].Value = '9' - $Worksheet.Cells[2, 5].Value = 'Thriller' - $Worksheet.Cells[3, 1].Value = 'The Matrix' - $Worksheet.Cells[3, 2].Value = '1999' - $Worksheet.Cells[3, 3].Value = '8' - $Worksheet.Cells[3, 5].Value = 'Sci-Fi' - $Worksheet.Cells[5, 1].Value = 'Skyfall' - $Worksheet.Cells[5, 2].Value = '2012' - $Worksheet.Cells[5, 3].Value = '9' - $Worksheet.Cells[5, 5].Value = 'Thriller' - - $Excel.Save() - $Excel.Dispose() - #endregion - - it 'Default' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'Movie name' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'Movie name' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'Movie name' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'Movie name' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'The Bodyguard' = 'The Matrix' - '1982' = '1999' - '9' = '8' - 'Thriller' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'The Bodyguard' = $null - '1982' = $null - '9' = $null - 'Thriller' = $null - } - [PSCustomObject]@{ - 'The Bodyguard' = 'Skyfall' - '1982' = '2012' - '9' = '9' - 'Thriller' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - {Import-Excel -Path $Path -WorksheetName Test -StartRow 4} | Should Throw 'No column headers found' - Import-Excel -Path $Path -WorksheetName Test -StartRow 5 | Should BeNullOrEmpty - } - it 'Default and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'Movie name' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'Movie name' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'Movie name' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'The Bodyguard' = 'The Matrix' - '1982' = '1999' - '9' = '8' - 'Thriller' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'The Bodyguard' = 'Skyfall' - '1982' = '2012' - '9' = '9' - 'Thriller' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - {Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 4} | Should Throw 'No column headers found' - - Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 5 | Should BeNullOrEmpty - } - it 'HeaderName' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = 'Year' - 'Rating' = 'Rating' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = 'Year' - 'Rating' = 'Rating' - 'Genre' = $null - 'Country' = 'Genre' - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -StartRow 4 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -StartRow 5 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -StartRow 6 | Should BeNullOrEmpty - } - it 'HeaderName and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = 'Year' - 'Rating' = 'Rating' - 'Genre' = 'Genre' - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - } - - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = 'Year' - 'Rating' = 'Rating' - 'Genre' = 'Genre' - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - 'Country' = $null - } - - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - } - - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = '1982' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = 'Sci-Fi' - 'Country' = $null - } - - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = $null - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly -StartRow 4 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly -StartRow 5 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly -StartRow 6 | Should BeNullOrEmpty - } - it 'NoHeader' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Movie name' - 'P2' = 'Year' - 'P3' = 'Rating' - 'P4' = $null - 'P5' = 'Genre' - } - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = '1982' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = $null - 'P4' = $null - 'P5' = $null - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = '1982' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = $null - 'P4' = $null - 'P5' = $null - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = $null - 'P4' = $null - 'P5' = $null - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - ) - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 4 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 5 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 6 | Should BeNullOrEmpty - } - it 'NoHeader and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Movie name' - 'P2' = 'Year' - 'P3' = 'Rating' - 'P4' = 'Genre' - } - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = '1982' - 'P3' = '9' - 'P4' = 'Thriller' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = '1982' - 'P3' = '9' - 'P4' = 'Thriller' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = 'Sci-Fi' - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = 'Thriller' - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = 'Thriller' - } - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 4 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 5 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 6 | Should BeNullOrEmpty - } - } - Describe 'blank rows and columns with missing headers' { - - #region Create test file - - # --------------------------------------------------------------------------------------------------- - # | A B C D E F G | - # |1 Movie name Rating Director | - # |2 The Bodyguard 9 Thriller Mick Jackson | - # |3 The Matrix 1999 8 Wachowski | - # |4 | - # |5 Skyfall 2012 9 Thriller Sam Mendes | - # |6 10 | - # --------------------------------------------------------------------------------------------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - - # Row, Column - $Worksheet.Cells[1, 1].Value = 'Movie name' - $Worksheet.Cells[1, 3].Value = 'Rating' - $Worksheet.Cells[1, 7].Value = 'Director' - $Worksheet.Cells[2, 1].Value = 'The Bodyguard' - $Worksheet.Cells[2, 3].Value = '9' - $Worksheet.Cells[2, 5].Value = 'Thriller' - $Worksheet.Cells[2, 7].Value = 'Mick Jackson' - $Worksheet.Cells[3, 1].Value = 'The Matrix' - $Worksheet.Cells[3, 2].Value = '1999' - $Worksheet.Cells[3, 3].Value = '8' - $Worksheet.Cells[3, 7].Value = 'Wachowski' - $Worksheet.Cells[5, 1].Value = 'Skyfall' - $Worksheet.Cells[5, 2].Value = '2012' - $Worksheet.Cells[5, 3].Value = '9' - $Worksheet.Cells[5, 5].Value = 'Thriller' - $Worksheet.Cells[5, 7].Value = 'Sam Mendes' - $Worksheet.Cells[6, 3].Value = '10' - - $Excel.Save() - $Excel.Dispose() - #endregion - - it 'Default' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'Movie name' = 'The Bodyguard' - 'Rating' = '9' - 'Director' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'Movie name' = 'The Matrix' - 'Rating' = '8' - 'Director' = 'Wachowski' - } - [PSCustomObject]@{ - 'Movie name' = $null - 'Rating' = $null - 'Director' = $null - } - [PSCustomObject]@{ - 'Movie name' = 'Skyfall' - 'Rating' = '9' - 'Director' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'Movie name' = $null - 'Rating' = '10' - 'Director' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'The Bodyguard' = 'The Matrix' - '9' = '8' - 'Thriller' = $null - 'Mick Jackson' = 'Wachowski' - } - [PSCustomObject]@{ - 'The Bodyguard' = $null - '9' = $null - 'Thriller' = $null - 'Mick Jackson' = $null - } - [PSCustomObject]@{ - 'The Bodyguard' = 'Skyfall' - '9' = '9' - 'Thriller' = 'Thriller' - 'Mick Jackson' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'The Bodyguard' = $null - '9' = '10' - 'Thriller' = $null - 'Mick Jackson' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'Movie name' = 'The Bodyguard' - 'Rating' = '9' - 'Director' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'Movie name' = 'The Matrix' - 'Rating' = '8' - 'Director' = 'Wachowski' - } - [PSCustomObject]@{ - 'Movie name' = 'Skyfall' - 'Rating' = '9' - 'Director' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'Movie name' = $null - 'Rating' = '10' - 'Director' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'Default, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'The Bodyguard' = 'The Matrix' - '9' = '8' - 'Thriller' = $null - 'Mick Jackson' = 'Wachowski' - } - [PSCustomObject]@{ - 'The Bodyguard' = 'Skyfall' - '9' = '9' - 'Thriller' = 'Thriller' - 'Mick Jackson' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'The Bodyguard' = $null - '9' = '10' - 'Thriller' = $null - 'Mick Jackson' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = $null - 'Rating' = 'Rating' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = $null - 'Rating' = 'Rating' - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = $null - 'Genre' = $null - 'Country' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = $null - 'Country' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = $null - 'Rating' = 'Rating' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'Movie name' - 'Year' = $null - 'Rating' = 'Rating' - 'Genre' = $null - 'Country' = 'Director' - } - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = 'Wachowski' - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'HeaderName, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - - $ExpectedResult = @( - [PSCustomObject]@{ - 'MovieName' = 'The Bodyguard' - 'Year' = $null - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'MovieName' = 'The Matrix' - 'Year' = '1999' - 'Rating' = '8' - 'Genre' = $null - 'Country' = 'Wachowski' - } - [PSCustomObject]@{ - 'MovieName' = 'Skyfall' - 'Year' = '2012' - 'Rating' = '9' - 'Genre' = 'Thriller' - 'Country' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'MovieName' = $null - 'Year' = $null - 'Rating' = '10' - 'Genre' = $null - 'Country' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -HeaderName MovieName, Year, Rating, Genre, Country -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Movie name' - 'P2' = $null - 'P3' = 'Rating' - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = 'Director' - } - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = $null - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - 'P6' = $null - 'P7' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = 'Wachowski' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = $null - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = $null - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - 'P6' = $null - 'P7' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = '10' - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = $null - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - 'P6' = $null - 'P7' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = 'Wachowski' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = $null - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = $null - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = $null - 'P5' = 'Thriller' - 'P6' = $null - 'P7' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = '10' - 'P4' = $null - 'P5' = $null - 'P6' = $null - 'P7' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader and DataOnly' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'Movie name' - 'P2' = $null - 'P3' = 'Rating' - 'P4' = $null - 'P5' = 'Director' - } - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = $null - 'P3' = '9' - 'P4' = 'Thriller' - 'P5' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = 'Wachowski' - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = 'Thriller' - 'P5' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = '10' - 'P4' = $null - 'P5' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'NoHeader, DataOnly and StartRow' { - $ExpectedResult = @( - [PSCustomObject]@{ - 'P1' = 'The Bodyguard' - 'P2' = $null - 'P3' = '9' - 'P4' = 'Thriller' - 'P5' = 'Mick Jackson' - } - [PSCustomObject]@{ - 'P1' = 'The Matrix' - 'P2' = '1999' - 'P3' = '8' - 'P4' = $null - 'P5' = 'Wachowski' - } - [PSCustomObject]@{ - 'P1' = 'Skyfall' - 'P2' = '2012' - 'P3' = '9' - 'P4' = 'Thriller' - 'P5' = 'Sam Mendes' - } - [PSCustomObject]@{ - 'P1' = $null - 'P2' = $null - 'P3' = '10' - 'P4' = $null - 'P5' = $null - } - ) - - $Result = Import-Excel -Path $Path -WorksheetName Test -NoHeader -DataOnly -StartRow 2 - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - } - } -} -#> -Context 'special cases' { - in $TestDrive { - #<# - Describe 'duplicate column headers' { - it 'worksheet' { - #region Create test file - - # ---------------------------------------------- - # | A B C | - # |1 First Name first name Address | - # |2 Chuck Norris California | - # |3 Jean-Claude Vandamme Brussels | - # ---------------------------------------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - - # Row, Column - $Worksheet.Cells[1, 1].Value = 'First Name' - $Worksheet.Cells[1, 2].Value = 'first name' - $Worksheet.Cells[1, 3].Value = 'Address' - $Worksheet.Cells[2, 1].Value = 'Chuck' - $Worksheet.Cells[2, 2].Value = 'Norris' - $Worksheet.Cells[2, 3].Value = 'California' - $Worksheet.Cells[3, 1].Value = 'Jean-Claude' - $Worksheet.Cells[3, 2].Value = 'Vandamme' - $Worksheet.Cells[3, 3].Value = 'Brussels' - - $Excel.Save() - $Excel.Dispose() - #endregion - - {Import-Excel -Path $Path -WorksheetName Test} | Should Throw 'Duplicate column headers found' - - #region Create test file - Remove-Item .\* -Force - - # ---------------------------------------------- - # | A B C | - # |1 | - # |2 Fruit Fruit Color | - # |3 Kiwi Green | - # ---------------------------------------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - - # Row, Column - $Worksheet.Cells[2, 1].Value = 'Fruit' - $Worksheet.Cells[2, 2].Value = 'Fruit' - $Worksheet.Cells[2, 3].Value = 'Color' - $Worksheet.Cells[3, 1].Value = 'Kiwi' - $Worksheet.Cells[3, 3].Value = 'Green' - - $Excel.Save() - $Excel.Dispose() - #endregion - - {Import-Excel -Path $Path -WorksheetName Test -StartRow 2} | Should Throw 'Duplicate column headers found' - } - it 'HeaderName parameter' { - {Import-Excel -Path $Path -WorksheetName Test -HeaderName Apples, Apples, Kiwi} | Should Throw 'Duplicate column headers found' - } - } - #> - Describe 'open password protected files' { - $Password = 'P@ssw0rd' - - #region Create password protected file - - # ---------------- - # | A | - # |1 Type | - # |2 Sensitive | - # ---------------- - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - - # Row, Column - $Worksheet = $Excel | Add-WorkSheet -WorkSheetname Test - $Worksheet.Cells[1, 1].Value = 'Type' - $Worksheet.Cells[2, 1].Value = 'Sensitive' - - $Excel.Save($Password) - $Excel.Dispose() - #endregion - - it 'password correct' { - $Result = Import-Excel -Path $Path -WorksheetName Test -Password $Password - - $ExpectedResult = [PSCustomObject]@{ - Type = 'Sensitive' - } - Assert-Equivalent -Actual $Result -Expected $ExpectedResult - } - it 'password wrong' { - {Import-Excel -Path $Path -WorksheetName Test -Password WrongPassword} | Should Throw 'Password' - } - } - } -} - -Context 'General Tests' { - in $TestDrive { - Describe 'Get Help' { - it 'New-Plot' { - #Get-Help : Unable to find type [PSPlot]. - {Help New-Plot} | Should -Not -Throw - } - } - } -} \ No newline at end of file diff --git a/Old_Export-Excel.Tests.ps1 b/Old_Export-Excel.Tests.ps1 deleted file mode 100644 index 62db210..0000000 --- a/Old_Export-Excel.Tests.ps1 +++ /dev/null @@ -1,94 +0,0 @@ -#Requires -Modules Pester - - -$here = Split-Path -Parent $MyInvocation.MyCommand.Path - - -Import-Module $here -Force - -$WarningPreference = 'SilentlyContinue' -$ProgressPreference = 'SilentlyContinue' - -Function Test-isNumeric { - Param ( - [Parameter(ValueFromPipeline)]$x - ) - - Return $x -is [byte] -or $x -is [int16] -or $x -is [int32] -or $x -is [int64] ` - -or $x -is [sbyte] -or $x -is [uint16] -or $x -is [uint32] -or $x -is [uint64] ` - -or $x -is [float] -or $x -is [double] -or $x -is [decimal] -} - -$fakeData = [PSCustOmobject]@{ - Property_1_Date = (Get-Date).ToString('d') # US '10/16/2017' BE '16/10/2107' - Property_2_Formula = '=SUM(G2:H2)' - Property_3_String = 'My String' - Property_4_String = 'a' - Property_5_IPAddress = '10.10.25.5' - Property_6_Number = '0' - Property_7_Number = '5' - Property_8_Number = '007' - Property_9_Number = (33).ToString('F2') # US '33.00' BE '33,00' - Property_10_Number = (5/3).ToString('F2') # US '1.67' BE '1,67' - Property_11_Number = (15999998/3).ToString('N2') # US '5,333,332.67' BE '5.333.332,67' - Property_12_Number = '1.555,83' - Property_13_PhoneNr = '+32 44' - Property_14_PhoneNr = '+32 4 4444 444' - Property_15_PhoneNr = '+3244444444' -} - -$Path = 'Test.xlsx' - -Describe 'Export-Excel' { - in $TestDrive { - Describe 'Number conversion' { - Context 'numerical values expected' { - #region Create test file - $fakeData | Export-Excel -Path $Path - - $Path = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Path) - $Excel = New-Object OfficeOpenXml.ExcelPackage $Path - $Worksheet = $Excel.Workbook.WorkSheets[1] - #endregion - - it 'zero' { - $fakeData.Property_6_Number | Should -BeExactly '0' - $Worksheet.Cells[2, 6].Text | Should -BeExactly $fakeData.Property_6_Number - $Worksheet.Cells[2, 6].Value | Test-isNumeric | Should -Be $true - } - - It 'regular number' { - $fakeData.Property_7_Number | Should -BeExactly '5' - $Worksheet.Cells[2, 7].Text | Should -BeExactly $fakeData.Property_7_Number - $Worksheet.Cells[2, 7].Value | Test-isNumeric | Should -Be $true - } - - It 'number starting with zero' { - $fakeData.Property_8_Number | Should -BeExactly '007' - $Worksheet.Cells[2, 8].Text | Should -BeExactly '7' - $Worksheet.Cells[2, 8].Value | Test-isNumeric | Should -Be $true - } - - It 'decimal number' { - # US '33.00' BE '33,00' - $fakeData.Property_9_Number | Should -BeExactly (33).ToString('F2') - $Worksheet.Cells[2, 9].Text | Should -BeExactly '33' - $Worksheet.Cells[2, 9].Value | Test-isNumeric | Should -Be $true - - # US '1.67' BE '1,67' - $fakeData.Property_10_Number | Should -BeExactly (5/3).ToString('F2') - $Worksheet.Cells[2, 10].Text | Should -BeExactly $fakeData.Property_10_Number - $Worksheet.Cells[2, 10].Value | Test-isNumeric | Should -Be $true - } - - It 'thousand seperator and decimal number' { - # US '5,333,332.67' BE '5.333.332,67' - # Excel BE '5333332,67' - $fakeData.Property_11_Number | Should -BeExactly (15999998/3).ToString('N2') - $Worksheet.Cells[2, 11].Text | Should -BeExactly $fakeData.Property_11_Number - $Worksheet.Cells[2, 11].Value | Test-isNumeric | Should -Be $true - } - } - } - } -} \ No newline at end of file From acdbd4a618aaeedab4c18e8609b3e3f5e8360a59 Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 13 Feb 2019 19:08:01 -0500 Subject: [PATCH 2/8] added demo --- Examples/OutTabulator/demo.txt | 23 ++ Examples/OutTabulator/start-demo.ps1 | 216 ++++++++++++++++++ Examples/OutTabulator/targetout.html | 80 +++++++ Examples/OutTabulator/tryConvertFromExcel.ps1 | 9 + 4 files changed, 328 insertions(+) create mode 100644 Examples/OutTabulator/demo.txt create mode 100644 Examples/OutTabulator/start-demo.ps1 create mode 100644 Examples/OutTabulator/targetout.html create mode 100644 Examples/OutTabulator/tryConvertFromExcel.ps1 diff --git a/Examples/OutTabulator/demo.txt b/Examples/OutTabulator/demo.txt new file mode 100644 index 0000000..0060900 --- /dev/null +++ b/Examples/OutTabulator/demo.txt @@ -0,0 +1,23 @@ +# ConvertFrom-Excel +'' + +.\test.xlsx + +Import-Excel .\test.xlsx | ft + +ConvertFrom-Excel -ExcelFile .\test.xlsx -outFile .\targetout.html + +# Create a column definition +$columnOptions = @() + +$columnOptions += New-ColumnOption -ColumnName Progress -formatter progress +ConvertFrom-Excel -ExcelFile .\test.xlsx -outFile .\targetout.html -columnOptions $columnOptions + +$columnOptions += New-ColumnOption Activity -formatter lineFormatter +ConvertFrom-Excel -ExcelFile .\test.xlsx -outFile .\targetout.html -columnOptions $columnOptions + +$columnOptions += New-ColumnOption -ColumnName Rating -formatter star +$columnOptions += New-ColumnOption Driver -formatter tickCross +ConvertFrom-Excel -ExcelFile .\test.xlsx -outFile .\targetout.html -columnOptions $columnOptions + +ConvertFrom-Excel -ExcelFile .\test.xlsx -outFile .\targetout.html -columnOptions $columnOptions -groupBy Gender \ No newline at end of file diff --git a/Examples/OutTabulator/start-demo.ps1 b/Examples/OutTabulator/start-demo.ps1 new file mode 100644 index 0000000..e5d4ada --- /dev/null +++ b/Examples/OutTabulator/start-demo.ps1 @@ -0,0 +1,216 @@ +## Start-Demo.ps1 +################################################################################################## +## This is an overhaul of Jeffrey Snover's original Start-Demo script by Joel "Jaykul" Bennett +## +## I've switched it to using ReadKey instead of ReadLine (you don't have to hit Enter each time) +## As a result, I've changed the names and keys for a lot of the operations, so that they make +## sense with only a single letter to tell them apart (sorry if you had them memorized). +## +## I've also been adding features as I come across needs for them, and you'll contribute your +## improvements back to the PowerShell Script repository as well. +################################################################################################## +## Revision History (version 3.3) +## 3.3.3 Fixed: Script no longer says "unrecognized key" when you hit shift or ctrl, etc. +## Fixed: Blank lines in script were showing as errors (now printed like comments) +## 3.3.2 Fixed: Changed the "x" to match the "a" in the help text +## 3.3.1 Fixed: Added a missing bracket in the script +## 3.3 - Added: Added a "Clear Screen" option +## - Added: Added a "Rewind" function (which I'm not using much) +## 3.2 - Fixed: Put back the trap { continue; } +## 3.1 - Fixed: No Output when invoking Get-Member (and other cmdlets like it???) +## 3.0 - Fixed: Commands which set a variable, like: $files = ls +## - Fixed: Default action doesn't continue +## - Changed: Use ReadKey instead of ReadLine +## - Changed: Modified the option prompts (sorry if you had them memorized) +## - Changed: Various time and duration strings have better formatting +## - Enhance: Colors are settable: prompt, command, comment +## - Added: NoPauseAfterExecute switch removes the extra pause +## If you set this, the next command will be displayed immediately +## - Added: Auto Execute mode (FullAuto switch) runs the rest of the script +## at an automatic speed set by the AutoSpeed parameter (or manually) +## - Added: Automatically append an empty line to the end of the demo script +## so you have a chance to "go back" after the last line of you demo +################################################################################################## +## +param( + $file=".\demo.txt", + [int]$command=0, + [System.ConsoleColor]$promptColor="Yellow", + [System.ConsoleColor]$commandColor="White", + [System.ConsoleColor]$commentColor="Green", + [switch]$FullAuto, + [int]$AutoSpeed = 3, + [switch]$NoPauseAfterExecute +) + +$RawUI = $Host.UI.RawUI +$hostWidth = $RawUI.BufferSize.Width + +# A function for reading in a character +function Read-Char() { + $_OldColor = $RawUI.ForeGroundColor + $RawUI.ForeGroundColor = "Red" + $inChar=$RawUI.ReadKey("IncludeKeyUp") + # loop until they press a character, so Shift or Ctrl, etc don't terminate us + while($inChar.Character -eq 0){ + $inChar=$RawUI.ReadKey("IncludeKeyUp") + } + $RawUI.ForeGroundColor = $_OldColor + return $inChar.Character +} + +function Rewind($lines, $index, $steps = 1) { + $started = $index; + $index -= $steps; + while(($index -ge 0) -and ($lines[$index].Trim(" `t").StartsWith("#"))){ + $index-- + } + if( $index -lt 0 ) { $index = $started } + return $index +} + +$file = Resolve-Path $file +while(-not(Test-Path $file)) { + $file = Read-Host "Please enter the path of your demo script (Crtl+C to cancel)" + $file = Resolve-Path $file +} + +Clear-Host + +$_lines = Get-Content $file +# Append an extra (do nothing) line on the end so we can still go back after the last line. +$_lines += "Write-Host 'The End'" +$_starttime = [DateTime]::now +$FullAuto = $false + +Write-Host -nonew -back black -fore $promptColor $(" " * $hostWidth) +Write-Host -nonew -back black -fore $promptColor @" +$(' ' * ($hostWidth -(18 + $(split-path $file -leaf).Length))) +"@ +Write-Host -nonew -back black -fore $promptColor "Press" +Write-Host -nonew -back black -fore Red " ? " +Write-Host -nonew -back black -fore $promptColor "for help.$(' ' * ($hostWidth -17))" +Write-Host -nonew -back black -fore $promptColor $(" " * $hostWidth) + +# We use a FOR and an INDEX ($_i) instead of a FOREACH because +# it is possible to start at a different location and/or jump +# around in the order. +for ($_i = $Command; $_i -lt $_lines.count; $_i++) +{ + # Put the current command in the Window Title along with the demo duration + $Dur = [DateTime]::Now - $_StartTime + $RawUI.WindowTitle = "$(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s {3}" -f + $dur.Hours, $dur.Minutes, $dur.Seconds, $($_Lines[$_i]) + + # Echo out the commmand to the console with a prompt as though it were real + Write-Host -nonew -fore $promptColor "[$_i]$([char]0x2265) " + if ($_lines[$_i].Trim(" ").StartsWith("#") -or $_lines[$_i].Trim(" ").Length -le 0) { + Write-Host -fore $commentColor "$($_Lines[$_i]) " + continue + } else { + Write-Host -nonew -fore $commandColor "$($_Lines[$_i]) " + } + + if( $FullAuto ) { Start-Sleep $autoSpeed; $ch = [char]13 } else { $ch = Read-Char } + switch($ch) + { + "?" { + Write-Host -Fore $promptColor @" + +Running demo: $file +(n) Next (p) Previous +(q) Quit (s) Suspend +(t) Timecheck (v) View $(split-path $file -leaf) +(g) Go to line by number +(f) Find lines by string +(a) Auto Execute mode +(c) Clear Screen +"@ + $_i-- # back a line, we're gonna step forward when we loop + } + "n" { # Next (do nothing) + Write-Host -Fore $promptColor "" + } + "p" { # Previous + Write-Host -Fore $promptColor "" + while ($_lines[--$_i].Trim(" ").StartsWith("#")){} + $_i-- # back a line, we're gonna step forward when we loop + } + "a" { # EXECUTE (Go Faster) + $AutoSpeed = [int](Read-Host "Pause (seconds)") + $FullAuto = $true; + Write-Host -Fore $promptColor "" + $_i-- # Repeat this line, and then just blow through the rest + } + "q" { # Quit + Write-Host -Fore $promptColor "" + $_i = $_lines.count; + break; + } + "v" { # View Source + $lines[0..($_i-1)] | Write-Host -Fore Yellow + $lines[$_i] | Write-Host -Fore Green + $lines[($_i+1)..$lines.Count] | Write-Host -Fore Yellow + $_i-- # back a line, we're gonna step forward when we loop + } + "t" { # Time Check + $dur = [DateTime]::Now - $_StartTime + Write-Host -Fore $promptColor $( + "{3} -- $(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s" -f + $dur.Hours, $dur.Minutes, $dur.Seconds, ([DateTime]::Now.ToShortTimeString())) + $_i-- # back a line, we're gonna step forward when we loop + } + "s" { # Suspend (Enter Nested Prompt) + Write-Host -Fore $promptColor "" + $Host.EnterNestedPrompt() + $_i-- # back a line, we're gonna step forward when we loop + } + "g" { # GoTo Line Number + $i = [int](Read-Host "line number") + if($i -le $_lines.Count) { + if($i -gt 0) { + # extra line back because we're gonna step forward when we loop + $_i = Rewind $_lines $_i (($_i-$i)+1) + } else { + $_i = -1 # Start negative, because we step forward when we loop + } + } + } + "f" { # Find by pattern + $match = $_lines | Select-String (Read-Host "search string") + if($match -eq $null) { + Write-Host -Fore Red "Can't find a matching line" + } else { + $match | % { Write-Host -Fore $promptColor $("[{0,2}] {1}" -f ($_.LineNumber - 1), $_.Line) } + if($match.Count -lt 1) { + $_i = $match.lineNumber - 2 # back a line, we're gonna step forward when we loop + } else { + $_i-- # back a line, we're gonna step forward when we loop + } + } + } + "c" { + Clear-Host + $_i-- # back a line, we're gonna step forward when we loop + } + "$([char]13)" { # on enter + Write-Host + trap [System.Exception] {Write-Error $_; continue;} + Invoke-Expression ($_lines[$_i]) | out-default + if(-not $NoPauseAfterExecute -and -not $FullAuto) { + $null = $RawUI.ReadKey("NoEcho,IncludeKeyUp") # Pause after output for no apparent reason... ;) + } + } + default + { + Write-Host -Fore Green "`nKey not recognized. Press ? for help, or ENTER to execute the command." + $_i-- # back a line, we're gonna step forward when we loop + } + } +} +$dur = [DateTime]::Now - $_StartTime +Write-Host -Fore $promptColor $( + "" -f + $dur.Hours, $dur.Minutes, $dur.Seconds, [DateTime]::Now.ToLongTimeString()) +Write-Host -Fore $promptColor $([DateTime]::now) +Write-Host \ No newline at end of file diff --git a/Examples/OutTabulator/targetout.html b/Examples/OutTabulator/targetout.html new file mode 100644 index 0000000..7da2bd6 --- /dev/null +++ b/Examples/OutTabulator/targetout.html @@ -0,0 +1,80 @@ + + + + + + + + Out-TabulatorView + + + + + + + + + + + +
+ + + + diff --git a/Examples/OutTabulator/tryConvertFromExcel.ps1 b/Examples/OutTabulator/tryConvertFromExcel.ps1 new file mode 100644 index 0000000..4372ba0 --- /dev/null +++ b/Examples/OutTabulator/tryConvertFromExcel.ps1 @@ -0,0 +1,9 @@ +[CmdletBinding()] +param($outFile = "$PSScriptRoot\targetout.html") + +$columnOptions = @() + +$columnOptions += New-ColumnOption -ColumnName Progress -formatter progress +$columnOptions += New-ColumnOption -ColumnName Activity -formatter lineFormatter + +ConvertFrom-Excel -ExcelFile $PSScriptRoot\test.xlsx -outFile $PSScriptRoot\targetout.html -columnOptions $columnOptions \ No newline at end of file From 736dd648f48bebffbe5c8564e9d93dc49d9013c9 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 17 Feb 2019 15:36:05 -0500 Subject: [PATCH 3/8] Updated git ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 39a724a..82c7631 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ testHide.ps1 ImportExcel.zip .vscode/launch.json +~$* From 639ca738f68f2e9b537a4d390b0f81da7bee78c9 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 17 Feb 2019 18:27:36 -0500 Subject: [PATCH 4/8] rearrange --- Examples/TestRestAPI/TestAPIReadXls.ps1 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Examples/TestRestAPI/TestAPIReadXls.ps1 b/Examples/TestRestAPI/TestAPIReadXls.ps1 index 954d9e2..2e9358d 100644 --- a/Examples/TestRestAPI/TestAPIReadXls.ps1 +++ b/Examples/TestRestAPI/TestAPIReadXls.ps1 @@ -7,6 +7,8 @@ function Test-APIReadXls { $WorksheetName = 'Sheet1' ) + $testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss.fff") + $records = Import-Excel $XlFilename $params = @{} @@ -35,7 +37,6 @@ function Test-APIReadXls { "@ }) - $testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss.fff") @" Describe "Tests from $($XlFilename) in $($WorksheetName)" { @@ -43,7 +44,5 @@ $($blocks) } "@ | Set-Content -Encoding Ascii $testFileName - #Invoke-Pester -Script (Get-ChildItem $testFileName) - Get-ChildItem $testFileName -} - + (Get-ChildItem $testFileName).FullName +} \ No newline at end of file From 2949ecc17353be2d460c2ecb24b5fef88e2377fb Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 17 Feb 2019 18:27:41 -0500 Subject: [PATCH 5/8] update --- Examples/TestRestAPI/testlist.xlsx | Bin 10353 -> 10353 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/Examples/TestRestAPI/testlist.xlsx b/Examples/TestRestAPI/testlist.xlsx index e0305409c4213cd11b21384094cdba315922531b..8cfe7785504b593ae27c3a37c9af2281ae0d42a5 100644 GIT binary patch delta 2543 zcmZ9OXE@sn8^)6;sVzpWm`&^vvj~SM6~qo|?;Ta+*cw%P^x$t-)z*Wm+Fb+<4y|3Y zh@u>|OKX(Az50&pI`8x4`SRSKp6kBv-@fU-Y2zFX(OKHL2Tlb7UC@9)%pedboFE$( z5aj0?5a1^h?oX(}u;!MrDQ5G*V9@{r0)FY}a?_Ic;llxidMWIsxl{;242~bUuL(4M=R^^R+>G~HY@fulyfP_2V)_6N34P(J`g%csTF~<7 z0lS)os(g^JWwE^OgwSShX29PMXw9rwiq@QeZ(MP8f5^A0&UVAVx^nnEJpM!Xb)v`d z9m?UM0ZX5lH9kjYj8>LoFX#r|b5dBK zT)(3ui*h0S@rcJh@s9PCp#6J)J~|4Lla`Rde?TZYyp8o}yZiZa=|0U!odXL4rqNR`t%o{KvxzDp$XwmMg7h9k1|2CaXVr^{v{e@^7gb zCcnJS(eS2knik)7i-y0}^G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990m^zN>wZJG5zbi z_Pd!avC!vOgI5snVyf%)$^a&g;Bk{>M2oK4iy+7+`$Q{q@B93-1iho8WIc>_S*ea* z`qk};`%1T1rU@;+Myn;gvRuTq1%{vAD8O-JT;RDt)jF+A+y29xVGj(B>N>p2UsqQ# z6C}y(79Hc#@8|3>-yZrR#+mV|!iB@6l%Q5%NaKqdP+X8pA z_=|fpt}1&B7j!M#RPOZq(|f}B`i>4-t{%+NhN7|HFFAV}2aRE~D`rrv}paCumq{u@7M<^5^ z%5i`dAV8(u6>!xV;FFv<{BL$U{nl_CAdt{M?Wf+lFyJbu2>*N4r-Fnz6(rvOEBGn~ ca41Lvhhk8!f8tmPfc@+_;N9s!6$QgT0T?l_p#T5? From 438be760f7601807a5c8e70275b6ba013e99c857 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 18 Feb 2019 13:51:50 -0500 Subject: [PATCH 6/8] updated --- Examples/TestRestAPI/ShowPesterResults.ps1 | 52 +++++++++------------ Examples/TestRestAPI/TestAPIReadXls.ps1 | 5 +- Examples/TestRestAPI/testlist.xlsx | Bin 10353 -> 10368 bytes 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Examples/TestRestAPI/ShowPesterResults.ps1 b/Examples/TestRestAPI/ShowPesterResults.ps1 index f66558b..aa3b7ba 100644 --- a/Examples/TestRestAPI/ShowPesterResults.ps1 +++ b/Examples/TestRestAPI/ShowPesterResults.ps1 @@ -1,40 +1,32 @@ function Show-PesterResults { - $xlfilename=".\test.xlsx" - rm $xlfilename -ErrorAction Ignore + $xlfilename = ".\test.xlsx" + Remove-Item $xlfilename -ErrorAction Ignore $ConditionalText = @() $ConditionalText += New-ConditionalText -Range "Result" -Text failed -BackgroundColor red -ConditionalTextColor black $ConditionalText += New-ConditionalText -Range "Result" -Text passed -BackgroundColor green -ConditionalTextColor black $ConditionalText += New-ConditionalText -Range "Result" -Text pending -BackgroundColor gray -ConditionalTextColor black - + $xlParams = @{ - Path=$xlfilename - WorkSheetname = 'PesterTests' - ConditionalText=$ConditionalText - PivotRows = 'Description' - PivotColumns = 'Result' - PivotData = @{'Result'='Count'} - IncludePivotTable = $true - #IncludePivotChart = $true - #NoLegend = $true - #ShowPercent = $true - #ShowCategory = $true - AutoSize = $true - AutoNameRange = $true - AutoFilter = $true - Show = $true + Path = $xlfilename + WorkSheetname = 'PesterTests' + ConditionalText = $ConditionalText + PivotRows = 'Result', 'Name' + PivotData = @{'Result' = 'Count'} + IncludePivotTable = $true + AutoSize = $true + AutoNameRange = $true + AutoFilter = $true + Show = $true } - $(foreach($result in (Invoke-Pester -PassThru -Show None).TestResult) { - - [PSCustomObject]@{ - Description = $result.Describe - Name = $result.Name - #Time = $result.Time - Result = $result.Result - Messge = $result.FailureMessage - StackTrace = $result.StackTrace - } - - }) | Sort Description | Export-Excel @xlParams + $(foreach ($result in (Invoke-Pester -PassThru -Show None).TestResult) { + [PSCustomObject]@{ + Description = $result.Describe + Name = $result.Name + Result = $result.Result + Messge = $result.FailureMessage + StackTrace = $result.StackTrace + } + }) | Sort-Object Description | Export-Excel @xlParams } \ No newline at end of file diff --git a/Examples/TestRestAPI/TestAPIReadXls.ps1 b/Examples/TestRestAPI/TestAPIReadXls.ps1 index 2e9358d..ff2e5d3 100644 --- a/Examples/TestRestAPI/TestAPIReadXls.ps1 +++ b/Examples/TestRestAPI/TestAPIReadXls.ps1 @@ -1,5 +1,3 @@ -try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} - function Test-APIReadXls { param( [parameter(Mandatory)] @@ -7,7 +5,7 @@ function Test-APIReadXls { $WorksheetName = 'Sheet1' ) - $testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss.fff") + $testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss") $records = Import-Excel $XlFilename @@ -37,7 +35,6 @@ function Test-APIReadXls { "@ }) - @" Describe "Tests from $($XlFilename) in $($WorksheetName)" { $($blocks) diff --git a/Examples/TestRestAPI/testlist.xlsx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WZ&1`10g zT%MP|#HjT1;e&UwgQfoZN@Y#q=u|T*rVC9n1tfV(p>s=Hj%4#oI#sHbUN*)+c)Lo% z1F_k!Rov$~pNuJR3U^W#l=*$wg!sQ8m?ull$CN1^Fs>0(6w_6(Sb12j==>PVeU^S! zi7rzkUZNzthDu09P?;z7Xc5gDB}dPWG#Peb0smV0!>Q~dxX4^8->lVjTlK{khkE7j z#IDFX7r3G!t3s(%+=%gB|K@2Eft&WzP7+W|cG%1#O2t13x0ub|)MZx1>vp2$-Lk>n zazM94O?uY9^wsvUj&P{X1GT+QU4wHW&$YG96=-1x*BVn9QD;|)!Qj~oC%n4ffTNVuPSFg_Z_#`FJh{BszL zhYKUfG9ma52<%EnjBJ}1&%q~(-@cOk_l~cS^1VU|{Ldl4AwQl=L>-91TZvq!RDk{6 F`xm=b&0YWi From d94db666d7ba54f1b4d179b043d36ee52879d7c5 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 18 Feb 2019 14:06:18 -0500 Subject: [PATCH 7/8] Added module --- Examples/TestRestAPI/PSExcelPester.psm1 | 90 +++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Examples/TestRestAPI/PSExcelPester.psm1 diff --git a/Examples/TestRestAPI/PSExcelPester.psm1 b/Examples/TestRestAPI/PSExcelPester.psm1 new file mode 100644 index 0000000..23e74a9 --- /dev/null +++ b/Examples/TestRestAPI/PSExcelPester.psm1 @@ -0,0 +1,90 @@ +function ConvertTo-PesterTest { + param( + [parameter(Mandatory)] + $XlFilename, + $WorksheetName = 'Sheet1' + ) + + $testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss") + + $records = Import-Excel $XlFilename + + $params = @{} + + $blocks = $(foreach ($record in $records) { + foreach ($propertyName in $record.psobject.properties.name) { + if ($propertyName -notmatch 'ExpectedResult|QueryString') { + $params.$propertyName = $record.$propertyName + } + } + + if ($record.QueryString) { + $params.Uri += "?{0}" -f $record.QueryString + } + + @" + + it "Should have the expected result '$($record.ExpectedResult)'" { + `$target = '$($params | ConvertTo-Json -compress)' | ConvertFrom-Json + + `$target.psobject.Properties.name | ForEach-Object {`$p=@{}} {`$p.`$_=`$(`$target.`$_)} + + Invoke-RestMethod @p | Should Be '$($record.ExpectedResult)' + } + +"@ + }) + + @" +Describe "Tests from $($XlFilename) in $($WorksheetName)" { +$($blocks) +} +"@ | Set-Content -Encoding Ascii $testFileName + + [PSCustomObject]@{ + TestFileName = (Get-ChildItem $testFileName).FullName + } +} + +function Show-PesterResult { + param( + [Parameter(ValueFromPipelineByPropertyName, Mandatory)] + $TestFileName + ) + + Begin { + $xlfilename = ".\test.xlsx" + Remove-Item $xlfilename -ErrorAction SilentlyContinue + + $ConditionalText = @() + $ConditionalText += New-ConditionalText -Range "Result" -Text failed -BackgroundColor red -ConditionalTextColor black + $ConditionalText += New-ConditionalText -Range "Result" -Text passed -BackgroundColor green -ConditionalTextColor black + $ConditionalText += New-ConditionalText -Range "Result" -Text pending -BackgroundColor gray -ConditionalTextColor black + + $xlParams = @{ + Path = $xlfilename + WorkSheetname = 'PesterTests' + ConditionalText = $ConditionalText + PivotRows = 'Result', 'Name' + PivotData = @{'Result' = 'Count'} + IncludePivotTable = $true + AutoSize = $true + AutoNameRange = $true + AutoFilter = $true + Show = $true + } + } + + End { + + $(foreach ($result in (Invoke-Pester -Script $TestFileName -PassThru -Show None).TestResult) { + [PSCustomObject][Ordered]@{ + Description = $result.Describe + Name = $result.Name + Result = $result.Result + Messge = $result.FailureMessage + StackTrace = $result.StackTrace + } + }) | Export-Excel @xlParams + } +} \ No newline at end of file From a4a989c556e7767a8b77fe3677b7e9996a33cc1e Mon Sep 17 00:00:00 2001 From: Doug Finke Date: Wed, 20 Feb 2019 19:26:43 -0500 Subject: [PATCH 8/8] Update Get-HtmlTable.ps1 --- Get-HtmlTable.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Get-HtmlTable.ps1 b/Get-HtmlTable.ps1 index 6a7427f..a64d320 100644 --- a/Get-HtmlTable.ps1 +++ b/Get-HtmlTable.ps1 @@ -1,3 +1,5 @@ +# https://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/ +# tweaked from the above code function Get-HtmlTable { param( [Parameter(Mandatory=$true)] @@ -39,4 +41,4 @@ function Get-HtmlTable { [PSCustomObject]$result } -} \ No newline at end of file +}