diff --git a/ColorCompletion.ps1 b/ColorCompletion.ps1 index bd91679..ac55254 100644 --- a/ColorCompletion.ps1 +++ b/ColorCompletion.ps1 @@ -27,6 +27,7 @@ if (Get-Command -Name register-argumentCompleter -ErrorAction SilentlyContinue) Register-ArgumentCompleter -CommandName New-ConditionalText -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Set-Format -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Set-Format -ParameterName FontColor -ScriptBlock $Function:ColorCompletion + Register-ArgumentCompleter -CommandName Set-Format -ParameterName BorderColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Set-Format -ParameterName PatternColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Set-Column -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Set-Column -ParameterName FontColor -ScriptBlock $Function:ColorCompletion diff --git a/README.md b/README.md index 0b9e99f..5fe5f93 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ iex (new-object System.Net.WebClient).DownloadString('https://raw.github.com/dfi - Quick charts in Export-excel were too wide (now 800 pixels instead of 1200), and now support show percent, ShowCategory and NoLegend Parameters - Fixed bug in Add-ExcelChart where XAxisPosition and YAxisPostion would not be set correctly - Fixed bug in Set-Format where enums with a value of zero, or zero numbers would not be set; added functionality to set-format to support -bold:$false -italic:$false etc. (see #400) -- Added tests for better coverage, and tweaked some tests to use few rows and/or columns for speed +- Added tests for better coverage (now at >80% average - set-row/colum set-format less than 80%) , and tweaked some tests to use few rows and/or columns for speed # What's new to 18th July 18 - Moved chart creation into its own function (Add-Excel chart) within Export-Excel.ps1. Renamed New-Excelchart to New-ExcelChartDefinition to make it clearer that it is not making anything in the workbook (but for compatibility put an alias of New-ExcelChart in so existing code does not break). Found that -Header does nothing, so it isn't Add-Excel chart and there is a message that does nothing in New-ExcelChartDefinition . diff --git a/Set-Row.ps1 b/Set-Row.ps1 index 2ce9805..1107f06 100644 --- a/Set-Row.ps1 +++ b/Set-Row.ps1 @@ -78,7 +78,7 @@ [int]$TextRotation , #Set cells to a fixed hieght [float]$Height, - #If Specified, return an ExcelPackage object to allow further work to be done on the file + #If Specified, return a row object to allow further work to be done [switch]$PassThru ) diff --git a/ToDo.md b/ToDo.md index f163574..ded5393 100644 --- a/ToDo.md +++ b/ToDo.md @@ -4,6 +4,9 @@ - [ ] Investigate regional support for number conversion & possible date conversion - [ ] Add help in ConvertToExcelXLSx.ps1, Get-HTMLTable.ps1, GetRange.PS1, GetExcelTable.Ps1, Import-HTML.PS1, New-ConditionalFormattingIconSet.Ps1, NewConditionalText.PS1, New-Psitem.PS1, Remove-Worksheet.ps1 and Add-ExcelChart - Copy parameter help from function Add-ExcelChart into New-ExcelChart.ps1 - [ ] Examples and tests for new "Quick charts" in Export Excel (replace examples) that use Charting.ps1, GetXYRange.ps1, InferData.PS1 (move these to deprecated). -- [ ] Refactor Set-Row and Set-Column to use set-format and add conditional format and return range support. -- [ ] Examples and tests for set-Row and Set-column +- [ ] Add conditional format and return range support to Set-Row and Set-Column to use set-format and +- [ ] Examples for set-Row and Set-column (e.g. from tests) - [ ] Add PivotTable can't select sheet by position. +- [ ] Increase code covereage for import-excel and Set-Format +- [ ] Wildcard support for hide worksheet, add show-worksheet, make worksheet active in Export-Excel + diff --git a/__tests__/Compare-WorkSheet.tests.ps1 b/__tests__/Compare-WorkSheet.tests.ps1 index 2a4255f..bb82bda 100644 --- a/__tests__/Compare-WorkSheet.tests.ps1 +++ b/__tests__/Compare-WorkSheet.tests.ps1 @@ -224,7 +224,7 @@ Describe "Merge Worksheet" { $ws.cells[5,1].Style.font.color.rgb | Should be "FF8b0000" $ws.cells[7,1].Style.font.color.rgb | Should be "FF8b0000" } - it "Set the background for the added / deleted /changed rows " { + it "Set the background for the added / deleted / changed rows " { $ws.cells["A3:E3"].style.Fill.BackgroundColor.Rgb | Should beNullOrEmpty $ws.cells["A4:E4"].style.Fill.BackgroundColor.Rgb | Should be "FFFFA500" $ws.cells["A5" ].style.Fill.BackgroundColor.Rgb | Should be "FF98FB98" diff --git a/__tests__/Export-Excel.Tests.ps1 b/__tests__/Export-Excel.Tests.ps1 index 2d3c4c0..cfd021e 100644 --- a/__tests__/Export-Excel.Tests.ps1 +++ b/__tests__/Export-Excel.Tests.ps1 @@ -302,8 +302,6 @@ Describe ExportExcel { } Context "#Example 5 # Adding a single conditional format " { - ### TODO New-ConditionalText doesn't a lot of options in Add-ConditionalFormat. - # It would be good to pull the logic out of Export-Excel and have EE call Add-ConditionalFormat. $ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink it "Created a Conditional format description " { $ct.BackgroundColor -is [System.Drawing.Color] | Should be $true @@ -407,7 +405,7 @@ Describe ExportExcel { #This time we are not deleting the XLSX file so this Should create a new, named, sheet. $Excel = Get-Process | Select-Object -first 50 -Property Name, cpu, pm, handles, company | Export-Excel $path -WorkSheetname Processes -PassThru #Testing -passthru and adding the Pivot as a second step. Want to save and re-open it ... - Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -NoTotalsInPivot + Export-Excel -ExcelPackage $Excel -WorkSheetname Processes -IncludePivotTable -PivotRows Company -PivotData PM -NoTotalsInPivot $Excel = Open-ExcelPackage $path $PTws = $Excel.Workbook.Worksheets["ProcessesPivotTable"] @@ -604,6 +602,7 @@ Describe ExportExcel { Set-Format -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold Set-Format -Address $sheet.Row(1) -Bold -HorizontalAlignment Center Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red + $rule = Add-ConditionalFormatting -passthru -Address $sheet.cells["C:C"] -RuleType TopPercent -ConditionValue 20 -Bold -StrikeThru Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red -Bold -Italic -Underline -BackgroundColor Beige -BackgroundPattern LightUp -PatternColor Gray foreach ($c in 5..9) {Set-Format $sheet.Column($c) -AutoFit } Add-PivotTable -PivotTableName "PT_Procs" -ExcelPackage $excel -SourceWorkSheet "Processes" -PivotRows Company -PivotData @{'Name' = 'Count'} -IncludePivotChart -ChartType ColumnClustered -NoLegend @@ -611,7 +610,11 @@ Describe ExportExcel { $excel = Open-ExcelPackage $path $sheet = $excel.Workbook.Worksheets["Processes"] - + it "Returned the rule when calling Add-ConditionalFormatting -passthur " { + $rule | should not beNullOrEmpty + $rule.getType().fullname | should be "OfficeOpenXml.ConditionalFormatting.ExcelConditionalFormattingTopPercent" + $rule.Style.Font.Strike | should be true + } it "Applied the formating " { $sheet | Should not beNullOrEmpty $sheet.Column(1).wdith | Should not be $sheet.DefaultColWidth @@ -635,6 +638,8 @@ Describe ExportExcel { $sheet.ConditionalFormatting[1].type | Should be 'GreaterThan' $sheet.ConditionalFormatting[1].Formula | Should be '104857600' $sheet.ConditionalFormatting[1].Style.Font.Color.Color.Name | Should be 'ffff0000' + $sheet.ConditionalFormatting[2].Style.Font.Strike | Should be $true + $sheet.ConditionalFormatting[2].type | Should be "TopPercent" } it "Froze the panes " { $sheet.view.Panes.Count | Should be 3 @@ -737,7 +742,7 @@ Describe ExportExcel { Select-Object -Property Name, @{n="TotalPm";e={($_.group | Measure-Object -sum -Property pm).sum }} | Export-Excel -NoHeader -AutoNameRange -path $path -ReturnRange -PieChart -ShowPercent $Cf = New-ConditionalFormattingIconSet -Range ($range -replace "^.*:","B2:") -ConditionalFormat ThreeIconSet -Reverse -IconType Flags - $ct = New-ConditionalText -Text "Microsoft" -ConditionalTextColor red -BackgroundColor AliceBlue -ConditionalType ContainsText + $ct = New-ConditionalText -Text "Microsoft" -ConditionalTextColor red -BackgroundColor AliceBlue -ConditionalType ContainsText it "Created the Conditional formatting rules " { $cf.Formatter | should be "ThreeIconSet" $cf.IconType | should be "Flags" @@ -749,22 +754,22 @@ Describe ExportExcel { $ct.Text | Should be "Microsoft" } - Export-Excel -Path $path -ConditionalFormat $cf -ConditionalText $ct + Export-Excel -Path $path -ConditionalFormat $cf -ConditionalText $ct $excel = Open-ExcelPackage -Path $path $rows = $range -replace "^.*?(\d+)$", '$1' $chart = $excel.Workbook.Worksheets["sheet1"].Drawings[0] $cFmt = $excel.Workbook.Worksheets["sheet1"].ConditionalFormatting it "Created the chart with the right series " { $chart.ChartType | should be "PieExploded3D" - $chart.series.series | should be "'Sheet1'!B1:B$rows" #would be B2 and A2 if we had a header. + $chart.series.series | should be "'Sheet1'!B1:B$rows" #would be B2 and A2 if we had a header. $chart.series.Xseries | should be "'Sheet1'!A1:A$rows" $chart.DataLabel.ShowPercent | should be $true } it "Created two Conditional formatting rules " { $cFmt.Count | should be $true $cFmt.Where({$_.type -eq "ContainsText"}) | Should not beNullOrEmpty - $cFmt.Where({$_.type -eq "ThreeIconSet"}) | Should not beNullOrEmpty - } + $cFmt.Where({$_.type -eq "ThreeIconSet"}) | Should not beNullOrEmpty + } } Context " # Awkward multiple tables" { diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index 28ecd87..494a876 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -16,14 +16,17 @@ Describe "Set-Column, Set-Row and Set Format" { $excel = $data| Export-Excel -Path $path -AutoNameRange -PassThru $ws = $excel.Workbook.Worksheets["Sheet1"] - Set-Column -Worksheet $ws -Heading "Total" -Value "=Quantity*Price" -NumberFormat "£#,###.00" -FontColor Blue -Bold -HorizontalAlignment Right -VerticalAlignment Top - Set-Row -Worksheet $ws -StartColumn 3 -BorderAround Thin -Italic -Underline -FontSize 14 -Value {"=sum($columnName`2:$columnName$endrow)" } -VerticalAlignment Bottom - Set-Format -Address $excel.Workbook.Worksheets["Sheet1"].cells["b3"]-HorizontalAlignment Right -VerticalAlignment Center -BorderAround Thick -BorderColor Red -StrikeThru - Set-Format -WorkSheet $ws -Range "E3" -Bold:$false -FontShift Superscript -HorizontalAlignment Left - Set-Format -WorkSheet $ws -Range "E1" -ResetFont -HorizontalAlignment General - Set-Format -Address $ws.cells["E7"] -ResetFont -WrapText -BackgroundColor AliceBlue -BackgroundPattern DarkTrellis -PatternColor Red -NumberFormat "£#,###.00" - Set-Format -Address $ws.Column(1) -Width 0 - Set-Format -Address $ws.row(5) -Height 0 + $c = Set-Column -PassThru -Worksheet $ws -Heading "Total" -Value "=Quantity*Price" -NumberFormat "£#,###.00" -FontColor Blue -Bold -HorizontalAlignment Right -VerticalAlignment Top + $r = Set-Row -PassThru -Worksheet $ws -StartColumn 3 -BorderAround Thin -Italic -Underline -FontSize 14 -Value {"=sum($columnName`2:$columnName$endrow)" } -VerticalAlignment Bottom + Set-Format -Address $excel.Workbook.Worksheets["Sheet1"].cells["b3"] -HorizontalAlignment Right -VerticalAlignment Center -BorderAround Thick -BorderColor Red -StrikeThru + Set-Format -Address $excel.Workbook.Worksheets["Sheet1"].cells["c3"] -BorderColor Red -BorderTop DashDot -BorderLeft DashDotDot -BorderBottom Dashed -BorderRight Dotted + Set-Format -WorkSheet $ws -Range "E3" -Bold:$false -FontShift Superscript -HorizontalAlignment Left + Set-Format -WorkSheet $ws -Range "E1" -ResetFont -HorizontalAlignment General + Set-Format -Address $ws.cells["E7"] -ResetFont -WrapText -BackgroundColor AliceBlue -BackgroundPattern DarkTrellis -PatternColor Red -NumberFormat "£#,###.00" + Set-Format -Address $ws.Column(1) -Width 0 + Set-Format -Address $ws.Column(2) -AutoFit + Set-Format -Address $ws.Cells["E:E"] -AutoFit + Set-Format -Address $ws.row(5) -Height 0 Close-ExcelPackage $excel $excel = Open-ExcelPackage $path @@ -31,6 +34,8 @@ Describe "Set-Column, Set-Row and Set Format" { } Context "Rows and Columns" { it "Set a row and a column to have zero width/height " { + $r | should not beNullorEmpty + $c | should not beNullorEmpty $ws.Column(1).width | should be 0 $ws.Row(5).height | should be 0 }