diff --git a/__tests__/Compare-WorkSheet.tests.ps1 b/__tests__/Compare-WorkSheet.tests.ps1 index bd01b55..d3d87d2 100644 --- a/__tests__/Compare-WorkSheet.tests.ps1 +++ b/__tests__/Compare-WorkSheet.tests.ps1 @@ -3,24 +3,24 @@ if ($PSVersionTable.PSVersion.Major -gt 5) { Write-Warning "Can't test grid view on V6 and later" } else {Add-Type -AssemblyName System.Windows.Forms } Describe "Compare Worksheet" { + BeforeAll { + Remove-Item -Path "TestDrive:\server*.xlsx" + [System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName + $s | Export-Excel -Path TestDrive:\server1.xlsx + #$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s + $row4Displayname = $s[2].DisplayName + $s[2].DisplayName = "Changed from the orginal" + $d = $s[-1] | Select-Object -Property * + $d.DisplayName = "Dummy Service" + $d.Name = "Dummy" + $s.Insert(3,$d) + $row6Name = $s[5].name + $s.RemoveAt(5) + $s | Export-Excel -Path TestDrive:\server2.xlsx + #Assume default worksheet name, (sheet1) and column header for key ("name") + $comp = compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" | Sort-Object -Property _row, _file + } Context "Simple comparison output" { - BeforeAll { - Remove-Item -Path "TestDrive:\server*.xlsx" - [System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName - $s | Export-Excel -Path TestDrive:\server1.xlsx - #$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s - $row4Displayname = $s[2].DisplayName - $s[2].DisplayName = "Changed from the orginal" - $d = $s[-1] | Select-Object -Property * - $d.DisplayName = "Dummy Service" - $d.Name = "Dummy" - $s.Insert(3,$d) - $row6Name = $s[5].name - $s.RemoveAt(5) - $s | Export-Excel -Path TestDrive:\server2.xlsx - #Assume default worksheet name, (sheet1) and column header for key ("name") - $comp = compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" | Sort-Object -Property _row, _file - } it "Found the right number of differences " { $comp | should not beNullOrEmpty $comp.Count | should be 4 @@ -55,7 +55,7 @@ Describe "Compare Worksheet" { $ModulePath = (Get-Command -Name 'Compare-WorkSheet').Module.Path $PowerShellExec = if ($PSEdition -eq 'Core') {'pwsh.exe'} else {'powershell.exe'} $PowerShellPath = Join-Path -Path $PSHOME -ChildPath $PowerShellExec - . $PowerShellPath -Command ("Import-Module $ModulePath; " + '$null = Compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView; Start-Sleep -sec 5') + . $PowerShellPath -Command ('Import-Module {0}; $null = Compare-WorkSheet "{1}Server1.xlsx" "{1}Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView; Start-Sleep -sec 5' -f $ModulePath, (Resolve-Path 'TestDrive:').ProviderPath) } else { $null = Compare-WorkSheet "TestDrive:\Server1.xlsx" "TestDrive:\Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView:$useGrid @@ -186,29 +186,29 @@ Describe "Compare Worksheet" { } Describe "Merge Worksheet" { + BeforeAll { + Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\Combined*.xlsx" -ErrorAction SilentlyContinue + [System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property * + + $s | Export-Excel -Path TestDrive:\server1.xlsx + + #$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s + $s[2].DisplayName = "Changed from the orginal" + + $d = $s[-1] | Select-Object -Property * + $d.DisplayName = "Dummy Service" + $d.Name = "Dummy" + $s.Insert(3,$d) + + $s.RemoveAt(5) + + $s | Export-Excel -Path TestDrive:\server2.xlsx + #Assume default worksheet name, (sheet1) and column header for key ("name") + Merge-Worksheet -Referencefile "TestDrive:\server1.xlsx" -Differencefile "TestDrive:\Server2.xlsx" -OutputFile "TestDrive:\combined1.xlsx" -Property name,displayname,startType -Key name + $excel = Open-ExcelPackage -Path "TestDrive:\combined1.xlsx" + $ws = $excel.Workbook.Worksheets["sheet1"] + } Context "Merge with 3 properties" { - BeforeAll { - Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\Combined*.xlsx" -ErrorAction SilentlyContinue - [System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property * - - $s | Export-Excel -Path TestDrive:\server1.xlsx - - #$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s - $s[2].DisplayName = "Changed from the orginal" - - $d = $s[-1] | Select-Object -Property * - $d.DisplayName = "Dummy Service" - $d.Name = "Dummy" - $s.Insert(3,$d) - - $s.RemoveAt(5) - - $s | Export-Excel -Path TestDrive:\server2.xlsx - #Assume default worksheet name, (sheet1) and column header for key ("name") - Merge-Worksheet -Referencefile "TestDrive:\server1.xlsx" -Differencefile "TestDrive:\Server2.xlsx" -OutputFile "TestDrive:\combined1.xlsx" -Property name,displayname,startType -Key name - $excel = Open-ExcelPackage -Path "TestDrive:\combined1.xlsx" - $ws = $excel.Workbook.Worksheets["sheet1"] - } it "Created a worksheet with the correct headings " { $ws | should not beNullOrEmpty $ws.Cells[ 1,1].Value | Should be "name" diff --git a/__tests__/Copy-ExcelWorksheet.Tests.ps1 b/__tests__/Copy-ExcelWorksheet.Tests.ps1 index b2d9bf0..d260522 100644 --- a/__tests__/Copy-ExcelWorksheet.Tests.ps1 +++ b/__tests__/Copy-ExcelWorksheet.Tests.ps1 @@ -1,36 +1,36 @@ -$path1 = "TestDrive:\Test1.xlsx" -$path2 = "TestDrive:\Test2.xlsx" -Remove-item -Path $path1, $path2 -ErrorAction SilentlyContinue - -$ProcRange = Get-Process | Export-Excel $path1 -DisplayPropertySet -WorkSheetname Processes -ReturnRange - -if ((Get-Culture).NumberFormat.CurrencySymbol -eq "£") {$OtherCurrencySymbol = "$"} -else {$OtherCurrencySymbol = "£"} -[PSCustOmobject][Ordered]@{ - Date = Get-Date - Formula1 = '=SUM(F2:G2)' - String1 = 'My String' - Float = [math]::pi - IPAddress = '10.10.25.5' - StrLeadZero = '07670' - StrComma = '0,26' - StrEngThousand = '1,234.56' - StrEuroThousand = '1.555,83' - StrDot = '1.2' - StrNegInt = '-31' - StrTrailingNeg = '31-' - StrParens = '(123)' - strLocalCurrency = ('{0}123.45' -f (Get-Culture).NumberFormat.CurrencySymbol ) - strOtherCurrency = ('{0}123.45' -f $OtherCurrencySymbol ) - StrE164Phone = '+32 (444) 444 4444' - StrAltPhone1 = '+32 4 4444 444' - StrAltPhone2 = '+3244444444' - StrLeadSpace = ' 123' - StrTrailSpace = '123 ' - Link1 = [uri]"https://github.com/dfinke/ImportExcel" - Link2 = "https://github.com/dfinke/ImportExcel" # Links are not copied correctly, hopefully this will be fixed at some future date -} | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -WorkSheetname MixedTypes -Path $path2 Describe "Copy-Worksheet" { + $path1 = "TestDrive:\Test1.xlsx" + $path2 = "TestDrive:\Test2.xlsx" + Remove-Item -Path $path1, $path2 -ErrorAction SilentlyContinue + + $ProcRange = Get-Process | Export-Excel $path1 -DisplayPropertySet -WorkSheetname Processes -ReturnRange + + if ((Get-Culture).NumberFormat.CurrencySymbol -eq "£") { $OtherCurrencySymbol = "$" } + else { $OtherCurrencySymbol = "£" } + [PSCustOmobject][Ordered]@{ + Date = Get-Date + Formula1 = '=SUM(F2:G2)' + String1 = 'My String' + Float = [math]::pi + IPAddress = '10.10.25.5' + StrLeadZero = '07670' + StrComma = '0,26' + StrEngThousand = '1,234.56' + StrEuroThousand = '1.555,83' + StrDot = '1.2' + StrNegInt = '-31' + StrTrailingNeg = '31-' + StrParens = '(123)' + strLocalCurrency = ('{0}123.45' -f (Get-Culture).NumberFormat.CurrencySymbol ) + strOtherCurrency = ('{0}123.45' -f $OtherCurrencySymbol ) + StrE164Phone = '+32 (444) 444 4444' + StrAltPhone1 = '+32 4 4444 444' + StrAltPhone2 = '+3244444444' + StrLeadSpace = ' 123' + StrTrailSpace = '123 ' + Link1 = [uri]"https://github.com/dfinke/ImportExcel" + Link2 = "https://github.com/dfinke/ImportExcel" # Links are not copied correctly, hopefully this will be fixed at some future date + } | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -WorkSheetname MixedTypes -Path $path2 Context "Simplest copy" { BeforeAll { Copy-ExcelWorkSheet -SourceWorkbook $path1 -DestinationWorkbook $path2 diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index 43fd806..622dbda 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -386,19 +386,19 @@ Describe ExportExcel { } } - Context "#Example 6 # Adding multiple conditional formats using short form syntax. " { - if ($notwindows) {Write-warning "Test only runs on Windows" ; return} - #Test adding mutliple conditional blocks and using the minimal syntax for new-ConditionalText - $path = "TestDrive:\Test.xlsx" - Remove-item -Path $path -ErrorAction SilentlyContinue + #Test adding mutliple conditional blocks and using the minimal syntax for new-ConditionalText + $path = "TestDrive:\Test.xlsx" + Remove-item -Path $path -ErrorAction SilentlyContinue - #Testing -Passthrough - $Excel = Get-Service | Select-Object Name, Status, DisplayName, ServiceName | - Export-Excel $path -PassThru -ConditionalText $( - New-ConditionalText Stop ([System.Drawing.Color]::DarkRed) ([System.Drawing.Color]::LightPink) - New-ConditionalText Running ([System.Drawing.Color]::Blue) ([System.Drawing.Color]::Cyan) - ) - $ws = $Excel.Workbook.Worksheets[1] + #Testing -Passthrough + $Excel = Get-Service | Select-Object Name, Status, DisplayName, ServiceName | + Export-Excel $path -PassThru -ConditionalText $( + New-ConditionalText Stop ([System.Drawing.Color]::DarkRed) ([System.Drawing.Color]::LightPink) + New-ConditionalText Running ([System.Drawing.Color]::Blue) ([System.Drawing.Color]::Cyan) + ) + $ws = $Excel.Workbook.Worksheets[1] + + Context "#Example 6 # Adding multiple conditional formats using short form syntax. " { it "Added two blocks of conditional formating for the data range " { $ws.ConditionalFormatting.Count | Should be 2 $ws.ConditionalFormatting[0].Address | Should be ($ws.Dimension.Address) @@ -411,8 +411,8 @@ Describe ExportExcel { $ws.ConditionalFormatting[1].Type | Should be "ContainsText" #Add RGB Comparison } - Close-ExcelPackage -ExcelPackage $Excel } + Close-ExcelPackage -ExcelPackage $Excel Context "#Example 7 # Update-FirstObjectProperties works " { $Array = @() @@ -991,7 +991,7 @@ Describe ExportExcel { } Context " # Parameters and ParameterSets" { - $Path = "TestDrive:\test.xlsx" + $Path = Join-Path (Resolve-Path 'TestDrive:').ProviderPath "test.xlsx" Remove-Item -Path $Path -ErrorAction SilentlyContinue $Processes = Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company diff --git a/__tests__/ExtraLongCmd.tests.ps1 b/__tests__/ExtraLongCmd.tests.ps1 index 026043a..8559a0d 100644 --- a/__tests__/ExtraLongCmd.tests.ps1 +++ b/__tests__/ExtraLongCmd.tests.ps1 @@ -1,9 +1,10 @@ if (-not $env:TEMP) {$env:TEMP = [IO.Path]::GetTempPath() -replace "/$","" } -$path = "TestDrive:\test.xlsx" -remove-item -path $path -ErrorAction SilentlyContinue -ConvertFrom-Csv @" +Describe "Creating workbook with a single line" { + $path = "TestDrive:\test.xlsx" + remove-item -path $path -ErrorAction SilentlyContinue + ConvertFrom-Csv @" Product, City, Gross, Net Apple, London , 300, 250 Orange, London , 400, 350 @@ -17,10 +18,9 @@ Apple, New York, 1200,700 PivotChartDefinition=@{Title="Gross and net by city and product"; ChartType="ColumnClustered"; Column=6; Width=600; Height=360; YMajorUnit=500; YMinorUnit=100; YAxisNumberformat="$#,##0"; LegendPosition="Bottom"}}} -$excel = Open-ExcelPackage $path -$ws1 = $excel.Workbook.Worksheets[1] -$ws2 = $excel.Workbook.Worksheets[2] -Describe "Creating workbook with a single line" { + $excel = Open-ExcelPackage $path + $ws1 = $excel.Workbook.Worksheets[1] + $ws2 = $excel.Workbook.Worksheets[2] Context "Data Page" { It "Inserted the data and created the table " { $ws1.Tables[0] | Should not beNullOrEmpty diff --git a/__tests__/ProtectWorksheet.tests.ps1 b/__tests__/ProtectWorksheet.tests.ps1 index f763535..28c65b7 100644 --- a/__tests__/ProtectWorksheet.tests.ps1 +++ b/__tests__/ProtectWorksheet.tests.ps1 @@ -1,6 +1,8 @@ -$path = "TestDrive:\test.xlsx" -Remove-Item -path $path -ErrorAction SilentlyContinue -$excel = ConvertFrom-Csv @" +Describe "Setting worksheet protection " { + BeforeAll { + $path = "TestDrive:\test.xlsx" + Remove-Item -path $path -ErrorAction SilentlyContinue + $excel = ConvertFrom-Csv @" Product, City, Gross, Net Apple, London , 300, 250 Orange, London , 400, 350 @@ -11,14 +13,11 @@ Apple, New York, 1200,700 "@ | Export-Excel -Path $path -WorksheetName Sheet1 -PassThru -$ws = $excel.sheet1 + $ws = $excel.sheet1 -Set-WorkSheetProtection -WorkSheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1" + Set-WorkSheetProtection -WorkSheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1" -Close-ExcelPackage -ExcelPackage $excel - -Describe "Setting worksheet protection " { - BeforeAll { + Close-ExcelPackage -ExcelPackage $excel $excel = Open-ExcelPackage -Path $path $ws = $ws = $excel.sheet1 } diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index aa2798d..2b6bac0 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -282,7 +282,7 @@ Describe "Set-ExcelColumn, Set-ExcelRow and Set-ExcelRange" { Describe "Conditional Formatting" { BeforeAll { - Remove-Item $path + #Remove-Item $path $data = Get-Process | Where-Object company | Select-Object company, name, pm, handles, *mem* $cfmt = New-ConditionalFormattingIconSet -Range "c:c" -ConditionalFormat ThreeIconSet -IconType Arrows $data | Export-Excel -path $Path -AutoSize -ConditionalFormat $cfmt @@ -357,7 +357,7 @@ Sold,ID Describe "Table Formatting" { BeforeAll { - Remove-Item $path + #Remove-Item $path $excel = $data2 | Export-excel -path $path -WorksheetName Hardware -AutoNameRange -AutoSize -BoldTopRow -FreezeTopRow -PassThru $ws = $excel.Workbook.Worksheets[1] #test showfilter & TotalSettings