From 438d7e2b030c2b837ed76cbbc5b51b3dc7ca5429 Mon Sep 17 00:00:00 2001 From: Thomas Hofkens Date: Sun, 25 Dec 2022 23:44:21 +0100 Subject: [PATCH 1/3] Fix Issue 1344 --- Public/Export-Excel.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Public/Export-Excel.ps1 b/Public/Export-Excel.ps1 index 9300a58..8f351d6 100644 --- a/Public/Export-Excel.ps1 +++ b/Public/Export-Excel.ps1 @@ -494,7 +494,7 @@ } elseif ($FreezeTopRow) { if ($Title) { - $ws.View.FreezePanes(2, 1) + $ws.View.FreezePanes(3, 1) Write-Verbose -Message "Froze title and header rows" } else { From 9373765e1082d7a53a985f9c50e8d9b7067c6a74 Mon Sep 17 00:00:00 2001 From: Thomas Hofkens Date: Mon, 26 Dec 2022 13:10:24 +0100 Subject: [PATCH 2/3] Introduced tests for Freezing panes --- __tests__/Export-Excel.Tests.ps1 | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index a964cce..3975bed 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -761,7 +761,13 @@ Describe ExportExcel -Tag "ExportExcel" { $path = "TestDrive:\test.xlsx" Remove-Item $path -ErrorAction SilentlyContinue #Test freezing top row/first column, adding formats and a pivot table - from Add-Pivot table not a specification variable - after the export - $excel = Get-Process | Select-Object -Property Name, Company, Handles, CPU, PM, NPM, WS | Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -FreezeTopRowFirstColumn -PassThru + $Ex13Data = Get-Process | Select-Object -Property Name, Company, Handles, CPU, PM, NPM, WS + $excel = $Ex13Data | Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -FreezeTopRowFirstColumn -PassThru + # Add extra worksheets for testing 'Freeze Top Row' and 'Freeze First Column' with or without title + $excel = Export-Excel -InputObject $Ex13Data -ExcelPackage $excel -WorksheetName "FreezeTopRow" -FreezeTopRow -Passthru + $excel = Export-Excel -InputObject $Ex13Data -ExcelPackage $excel -WorksheetName "FreezeFirstColumn" -FreezeFirstColumn -Passthru + $excel = Export-Excel -InputObject $Ex13Data -Title "Freeze Top Row" -ExcelPackage $excel -WorksheetName "FreezeTopRowTitle" -FreezeTopRow -Passthru + $excel = Export-Excel -InputObject $Ex13Data -Title "Freeze Top Row First Column" -ExcelPackage $excel -WorksheetName "FreezeTRFCTitle" -FreezeTopRowFirstColumn -Passthru $sheet = $excel.Workbook.Worksheets["Processes"] if ($isWindows) { $sheet.Column(1) | Set-ExcelRange -Bold -AutoFit } else { $sheet.Column(1) | Set-ExcelRange -Bold } @@ -781,6 +787,10 @@ Describe ExportExcel -Tag "ExportExcel" { $excel = Open-ExcelPackage $path $sheet = $excel.Workbook.Worksheets["Processes"] + $sheetftr = $excel.Workbook.Worksheets["FreezeTopRow"] + $sheetffc = $excel.Workbook.Worksheets["FreezeFirstColumn"] + $sheetftrt = $excel.Workbook.Worksheets["FreezeTopRowTitle"] + $sheetftrfct = $excel.Workbook.Worksheets["FreezeTRFCTitle"] } it "Returned the rule when calling Add-ConditionalFormatting -passthru " { $rule | Should -Not -BeNullOrEmpty @@ -827,7 +837,27 @@ Describe ExportExcel -Tag "ExportExcel" { $sheet.Names[6].Name | Should -Be $sheet.Cells['G1'].Value } it "Froze the panes " { - $sheet.view.Panes.Count | Should -Be 3 + $sheetPaneInfo = $sheet.worksheetxml.worksheet.sheetViews.sheetView.pane + $sheetftrPaneInfo = $sheetftr.worksheetxml.worksheet.sheetViews.sheetView.pane + $sheetffcPaneInfo = $sheetffc.worksheetxml.worksheet.sheetViews.sheetView.pane + $sheetftrtPaneInfo = $sheetftrt.worksheetxml.worksheet.sheetViews.sheetView.pane + $sheetftrfctPaneInfo = $sheetftrfct.worksheetxml.worksheet.sheetViews.sheetView.pane + $sheet.view.Panes.Count | Should -Be 3 # Don't know if this actually checks anything + $sheetPaneInfo.xSplit | Should -Be 1 + $sheetPaneInfo.ySplit | Should -Be 1 + $sheetPaneInfo.topLeftCell | Should -Be "B2" + $sheetftrPaneInfo.xSplit | Should -BeNullOrEmpty + $sheetftrPaneInfo.ySplit | Should -Be 1 + $sheetftrPaneInfo.topLeftCell | Should -Be "A2" + $sheetffcPaneInfo.xSplit | Should -Be 1 + $sheetffcPaneInfo.ySplit | Should -BeNullOrEmpty + $sheetffcPaneInfo.topLeftCell | Should -Be "B1" + $sheetftrtPaneInfo.xSplit | Should -BeNullOrEmpty + $sheetftrtPaneInfo.ySplit | Should -Be 2 + $sheetftrtPaneInfo.topLeftCell | Should -Be "A3" + $sheetftrfctPaneInfo.xSplit | Should -Be 1 + $sheetftrfctPaneInfo.ySplit | Should -Be 2 + $sheetftrfctPaneInfo.topLeftCell | Should -Be "B3" } it "Created the pivot table " { From 0fe6654233466bc4b6d9211c84b3af87807f1866 Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 28 Dec 2022 14:16:14 -0500 Subject: [PATCH 3/3] Add additional test --- __tests__/Export-Excel.Tests.ps1 | 48 ++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index 3975bed..9e726dc 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -693,11 +693,11 @@ Describe ExportExcel -Tag "ExportExcel" { # Export as table with a totals row with a set of possibilities $TableTotalSettings = @{ - Id = "COUNT" - WS = "SUM" - Handles = "AVERAGE" - CPU = '=COUNTIF([CPU];"<1")' - NPM = @{ + Id = "COUNT" + WS = "SUM" + Handles = "AVERAGE" + CPU = '=COUNTIF([CPU];"<1")' + NPM = @{ Function = '=SUMIF([Name];"=Chrome";[NPM])' Comment = "Sum of Non-Paged Memory (NPM) for all chrome processes" } @@ -1228,4 +1228,42 @@ Describe ExportExcel -Tag "ExportExcel" { Close-ExcelPackage $excel -NoSave } } + + It "Should freeze the correct rows" -tag Freeze { + <# + Export-Excel -InputObject $Data -Path $OutputFile -TableName $SheetName.Replace(' ', '_') -WorksheetName $SheetName -AutoSize -FreezeTopRow -TableStyle $TableStyle -Title $SheetName -TitleBold -TitleSize 18 + #> + + $path = "TestDrive:\testFreeze.xlsx" + + $data = ConvertFrom-Csv @" + Region,State,Units,Price + West,Texas,927,923.71 + North,Tennessee,466,770.67 + East,Florida,520,458.68 + East,Maine,828,661.24 + West,Virginia,465,053.58 + North,Missouri,436,235.67 + South,Kansas,214,992.47 + North,North Dakota,789,640.72 + South,Delaware,712,508.55 +"@ + + Export-Excel -InputObject $data -Path $path -TableName 'TestTable' -WorksheetName 'TestSheet' -AutoSize -TableStyle Medium2 -Title 'Test Title' -TitleBold -TitleSize 18 -FreezeTopRow + + $excel = Open-ExcelPackage -Path $path + $ws = $excel.TestSheet + + $r = $ws.worksheetxml.worksheet.sheetViews.sheetView.pane + + $r | Should -Not -BeNullOrEmpty + $r.ySplit | Should -Be 2 + $r.topLeftCell | Should -BeExactly 'A3' + $r.state | Should -BeExactly 'frozen' + $r.activePane | Should -BeExactly 'bottomLeft' + + Close-ExcelPackage $excel + + Remove-Item $path + } } \ No newline at end of file