From 3afe2059e528ca1c30f197f0f639f4ef28201150 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Tue, 20 Nov 2018 10:52:29 +0000 Subject: [PATCH 01/17] Added message to say title is ignored when exporting with -Append. --- Export-Excel.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 8e955b3..6b239ae 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -674,6 +674,7 @@ $row = $ws.Dimension.End.Row Write-Debug -Message ("Appending: headers are " + ($script:Header -join ", ") + " Start row is $row") + if ($Title) {Write-Warning -Message "-Title Parameter is ignored when appending."} } elseif ($Title) { #Can only add a title if not appending! From 2753a6876a41dcd9265ef60d4d840111ac7dfa03 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Tue, 27 Nov 2018 11:03:06 +0000 Subject: [PATCH 02/17] Better handling of Empry values when setting Columns/Rows --- Set-Column.ps1 | 15 ++++++++------- Set-Row.ps1 | 3 ++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Set-Column.ps1 b/Set-Column.ps1 index e0eeebd..73c93f7 100644 --- a/Set-Column.ps1 +++ b/Set-Column.ps1 @@ -156,10 +156,11 @@ if ($PSBoundParameters.ContainsKey('Value')) { foreach ($row in ($StartRow..$endRow)) { if ($Value -is [scriptblock]) { #re-create the script block otherwise variables from this function are out of scope. $cellData = & ([scriptblock]::create( $Value )) - Write-Verbose -Message $cellData + if ($null -eq $cellData) {Write-Verbose -Message "Script block evaluates to null."} + else {Write-Verbose -Message "Script block evaluates to '$cellData'"} } else { $cellData = $Value} - if ($cellData -match "^=") { $Worksheet.Cells[$Row, $Column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care + if ($cellData -match "^=") { $Worksheet.Cells[$Row, $Column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care elseif ( [System.Uri]::IsWellFormedUriString($cellData , [System.UriKind]::Absolute)) { # Save a hyperlink : internal links can be in the form xl://sheet!E419 (use A1 as goto sheet), or xl://RangeName if ($cellData -match "^xl://internal/") { @@ -168,13 +169,13 @@ $h = New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList $referenceAddress , $display $Worksheet.Cells[$Row, $Column].HyperLink = $h } - else {$Worksheet.Cells[$Row, $Column].HyperLink = $cellData } - $Worksheet.Cells[$Row, $Column].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) + else {$Worksheet.Cells[$Row, $Column].HyperLink = $cellData } $Worksheet.Cells[$Row, $Column].Style.Font.UnderLine = $true + $Worksheet.Cells[$Row, $Column].Style.Font.Color.SetColor([System.Drawing.Color]::Blue) } - else { $Worksheet.Cells[$Row, $Column].Value = $cellData } - if ($cellData -is [datetime]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = 'm/d/yy h:mm' } # This is not a custom format, but a preset recognized as date and localized. - if ($cellData -is [timespan]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = '[h]:mm:ss' } + else { $Worksheet.Cells[$Row, $Column].Value = $cellData } + if ($cellData -is [datetime]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = 'm/d/yy h:mm' } # This is not a custom format, but a preset recognized as date and localized. + if ($cellData -is [timespan]) { $Worksheet.Cells[$Row, $Column].Style.Numberformat.Format = '[h]:mm:ss' } }} #region Apply formatting diff --git a/Set-Row.ps1 b/Set-Row.ps1 index fe385c8..1fd6a1f 100644 --- a/Set-Row.ps1 +++ b/Set-Row.ps1 @@ -147,7 +147,8 @@ if ($Value -is [scriptblock] ) { #re-create the script block otherwise variables from this function are out of scope. $cellData = & ([scriptblock]::create( $Value )) - Write-Verbose -Message $cellData + if ($null -eq $cellData) {Write-Verbose -Message "Script block evaluates to null."} + else {Write-Verbose -Message "Script block evaluates to '$cellData'"} } else{$cellData = $Value} if ($cellData -match "^=") { $Worksheet.Cells[$Row, $column].Formula = ($cellData -replace '^=','') } #EPPlus likes formulas with no = sign; Excel doesn't care From f86fdbab22f9873afbcad5f1cfc10cf41cd0a812 Mon Sep 17 00:00:00 2001 From: "azure-pipelines[bot]" Date: Fri, 30 Nov 2018 14:46:43 +0000 Subject: [PATCH 03/17] Set up CI with Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4665bdd..d6a1111 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,7 +3,7 @@ resources: queue: name: Hosted VS2017 steps: -- powershell: ./ '.\DoTests.ps1' +- powershell: '.\DoTests.ps1' displayName: 'PowerShell Script' - task: ArchiveFiles@2 From 1dc9a02d7dd4be95f7b01578dcd97887340c63de Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:05:58 +0000 Subject: [PATCH 04/17] Updates to azure pipeline --- DoTests.ps1 | 7 +++++-- azure-pipelines.yml | 3 --- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index ce81979..ae52d13 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -7,18 +7,21 @@ param( ## $PSVersionTable.PSVersion +$env:BUILD_ARTIFACTSTAGINGDIRECTORY +$VerbosePreference = "Continue" ## Create the zip before the tests run ## Otherwise the EPPlus.dll is in use after the Pester run $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | ForEach-Object ModuleVersion if (!$DontCreateZip) { + if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} $dest = "ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss") - Compress-Archive -Path . -DestinationPath .\$dest + Compress-Archive -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -DestinationPath .\$dest -Verbose } if ($null -eq (Get-Module -ListAvailable pester)) { - Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser + Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser -Verbose } $result = Invoke-Pester -Script $PSScriptRoot\__tests__ -Verbose -PassThru diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 4665bdd..0c02519 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,9 +6,6 @@ steps: - powershell: ./ '.\DoTests.ps1' displayName: 'PowerShell Script' -- task: ArchiveFiles@2 - displayName: 'Archive $(Build.BinariesDirectory)' - trigger: paths: exclude: From 77481f2901649b6d2b2882d504909f0c1b159560 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:18:46 +0000 Subject: [PATCH 05/17] More of the same --- DoTests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index ae52d13..d17731a 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -16,8 +16,8 @@ $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | Fo if (!$DontCreateZip) { if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} - $dest = "ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss") - Compress-Archive -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -DestinationPath .\$dest -Verbose + $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) + Compress-Archive -Path . -DestinationPath .\$dest -Verbose } if ($null -eq (Get-Module -ListAvailable pester)) { From 234615dfdb0bb154041c03c6fdafd3b7cf05716b Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:25:02 +0000 Subject: [PATCH 06/17] path fix --- DoTests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/DoTests.ps1 b/DoTests.ps1 index d17731a..31dda9a 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -16,6 +16,7 @@ $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | Fo if (!$DontCreateZip) { if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} + elseif (-not (test-path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -PathType Container)) {mkdir -path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Verbose} $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) Compress-Archive -Path . -DestinationPath .\$dest -Verbose } From 284560e1091a805fe9a5b530a5c26b42b7477a40 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:26:45 +0000 Subject: [PATCH 07/17] One more --- DoTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 31dda9a..68e1bcd 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -18,7 +18,7 @@ if (!$DontCreateZip) { if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} elseif (-not (test-path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -PathType Container)) {mkdir -path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Verbose} $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) - Compress-Archive -Path . -DestinationPath .\$dest -Verbose + Compress-Archive -Path . -DestinationPath $dest -Verbose } if ($null -eq (Get-Module -ListAvailable pester)) { From eca631670c63956b5b3059ba417f99d4b69abed3 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:33:06 +0000 Subject: [PATCH 08/17] Update azure-pipelines.yml --- azure-pipelines.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dc2278b..d7f4cc9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,7 +6,12 @@ steps: - powershell: '.\DoTests.ps1' displayName: 'PowerShell Script' +- task: PublishBuildArtifacts@1 + inputs: + pathtoPublish: '$(Build.ArtifactStagingDirectory)' + artifactName: drop1 + trigger: paths: exclude: - - README.md \ No newline at end of file + - README.md From 268d48ce3d947d2da7a5456b52bb1acd5b224572 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:45:11 +0000 Subject: [PATCH 09/17] Take verbose back out of DoTests --- DoTests.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 68e1bcd..9692e78 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -9,7 +9,6 @@ param( $PSVersionTable.PSVersion $env:BUILD_ARTIFACTSTAGINGDIRECTORY -$VerbosePreference = "Continue" ## Create the zip before the tests run ## Otherwise the EPPlus.dll is in use after the Pester run $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | ForEach-Object ModuleVersion @@ -29,4 +28,4 @@ $result = Invoke-Pester -Script $PSScriptRoot\__tests__ -Verbose -PassThru if ($result.FailedCount -gt 0) { throw "$($result.FailedCount) tests failed." -} \ No newline at end of file +} From c5cc018eb588b4465b4f363caf34db0544deea1b Mon Sep 17 00:00:00 2001 From: jhoneill Date: Fri, 30 Nov 2018 16:58:08 +0000 Subject: [PATCH 10/17] Update DoTests.ps1 --- DoTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 9692e78..2d2aa9d 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -3,7 +3,7 @@ param( ) ## -# Used in Appveyor.yml +# Called by Azure Devops ## $PSVersionTable.PSVersion From 2981bf23b143bc06b4f2551bd9edb98591059cf8 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 17:45:10 +0000 Subject: [PATCH 11/17] Added Pivot table grouping --- PivotTable.ps1 | 82 +++++++++++++++++++++++++++++++- __tests__/First10Races.tests.ps1 | 44 +++++++++++++++-- 2 files changed, 121 insertions(+), 5 deletions(-) diff --git a/PivotTable.ps1 b/PivotTable.ps1 index 48bc257..247fd4d 100644 --- a/PivotTable.ps1 +++ b/PivotTable.ps1 @@ -38,7 +38,51 @@ but here -Address is specified to place it beside the data. The Add-Pivot table is given the chart definition and told to create a tale using the City field to create rows, the Product field to create columns and the data should be the sum of the gross field and the sum of the net field; grand totals for both gross and net are included for rows (Cities) and columns (product) and the data is explicitly formatted as a currency. - Not that in the chart definition the number format for the axis does not include any fraction part. + Note that in the chart definition the number format for the axis does not include any fraction part. + .Example + > + $excel = Convertfrom-csv @" + Location,OrderDate,quantity + Boston,1/1/2017,100 + New York,1/21/2017,200 + Boston,1/11/2017,300 + New York,1/9/2017,400 + Boston,1/18/2017,500 + Boston,2/1/2017,600 + New York,2/21/2017,700 + New York,2/11/2017,800 + Boston,2/9/2017,900 + Boston,2/18/2017,1000 + New York,1/1/2018,100 + Boston,1/21/2018,200 + New York,1/11/2018,300 + Boston,1/9/2018,400 + New York,1/18/2018,500 + Boston,2/1/2018,600 + Boston,2/21/2018,700 + New York,2/11/2018,800 + New York,2/9/2018,900 + Boston,2/18/2018,1000 + "@ | Select-Object -Property @{n="OrderDate";e={[datetime]::ParseExact($_.OrderDate,"M/d/yyyy",(Get-Culture))}}, + Location, Quantity | Export-Excel "test2.xlsx" -PassThru -AutoSize + + Set-ExcelColumn -Worksheet $excel.sheet1 -Column 1 -NumberFormat 'Short Date' + + $pt = Add-PivotTable -PassThru -PivotTableName "ByDate" -Address $excel.Sheet1.cells["F1"] -SourceWorkSheet $excel.Sheet1 -PivotRows location,orderdate -PivotData @{'quantity'='sum'} -GroupDateRow orderdate -GroupDatePart 'Months,Years' -PivotTotals None + $pt.RowFields[0].SubtotalTop=$false + $pt.RowFields[0].Compact=$false + Close-ExcelPackage $excel -Show + + Here the data contains dates formatted as strings using US format. These + are converted to DateTime objects before being exported to Excel; the + "OrderDate" column is formatted with the local short-date style. Then + the PivotTable is added; it groups information by date and location, the + date is split into years and then months. No grand totals are displayed. + The Pivot table object is caught in a variable, and the "Location" + column has its subtotal moved from the top to the bottom of each location + section, and the "Compact" option is disabled to prevent "Year" moving + into the same column as location. + Finally the workbook is saved and shown in Excel. #> [cmdletbinding(defaultParameterSetName='ChartbyParams')] [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] @@ -71,6 +115,18 @@ [String]$PivotTotals = "Both", #Included for compatibility - equivalent to -PivotTotals "None". [Switch]$NoTotalsInPivot, + #The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + [String]$GroupDateRow, + #The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, + #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + [String]$GroupNumericRow, + #The starting point for grouping + [double]$GroupNumbericMin = 0 , + #The endpoint for grouping + [double]$GroupNumbericMax = [Double]::MaxValue , + #The interval for grouping + [double]$GroupNumbericInterval = 100 , #Number format to apply to the data cells in the PivotTable. [string]$PivotNumberFormat, #Apply a table style to the PivotTable. @@ -198,7 +254,17 @@ if ($PivotTotals -eq "None" -or $PivotTotals -eq "Rows") { $pivotTable.ColumGrandTotals = $false } # Epplus spelling mistake, not mine! elseif ($PivotTotals -eq "Both" -or $PivotTotals -eq "Columns") { $pivotTable.ColumGrandTotals = $true } if ($PivotDataToColumn ) { $pivotTable.DataOnRows = $false } - if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle} + if ($PivotTableStyle) { $pivotTable.TableStyle = $PivotTableStyle} + if ($GroupNumericRow) { + $r =$pivotTable.RowFields.Where({$_.name -eq $GroupNumericRow }) + if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupNumericRow'; no numeric grouping will be done."} + else {$r.AddNumericGrouping($GroupNumbericMin,$GroupNumbericMax,$GroupNumbericInterval)} + } + if ($GroupDateRow -and $PSBoundParameters.ContainsKey("GroupDatePart")) { + $r =$pivotTable.RowFields.Where({$_.name -eq $GroupDateRow }) + if (-not $r ) {Write-Warning -Message "Could not find a Row field named '$GroupDateRow'; no date grouping will be done."} + else {$r.AddDateGrouping($GroupDatePart)} + } } catch {Write-Warning -Message "Failed adding PivotTable '$pivotTableName': $_"} } @@ -271,6 +337,18 @@ function New-PivotTableDefinition { [String]$PivotTotals = "Both", #Included for compatibility - equivalent to -PivotTotals "None" [Switch]$NoTotalsInPivot, + #The name of a row field which should be grouped by parts of the date/time (ignored if GroupDateRow is not specified) + [String]$GroupDateRow, + #The Part(s) of the date to use in the grouping (ignored if GroupDateRow is not specified) + [OfficeOpenXml.Table.PivotTable.eDateGroupBy[]]$GroupDatePart, + #The name of a row field which should be grouped by Number (e.g 0-99, 100-199, 200-299 ) + [String]$GroupNumericRow, + #The starting point for grouping + [double]$GroupNumbericMin = 0 , + #The endpoint for grouping + [double]$GroupNumbericMax = [Double]::MaxValue , + #The interval for grouping + [double]$GroupNumbericInterval = 100 , #Number format to apply to the data cells in the PivotTable [string]$PivotNumberFormat, #Apply a table style to the PivotTable diff --git a/__tests__/First10Races.tests.ps1 b/__tests__/First10Races.tests.ps1 index a86754b..1102941 100644 --- a/__tests__/First10Races.tests.ps1 +++ b/__tests__/First10Races.tests.ps1 @@ -6,7 +6,9 @@ Describe "Creating small named ranges with hyperlinks" { $path = "$env:TEMP\Results.xlsx" Remove-Item -Path $path -ErrorAction SilentlyContinue #Read race results, and group by race name : export 1 row to get headers, leaving enough rows aboce to put in a link for each race - $results = Import-Csv -Path $dataPath | Group-Object -Property RACE + $results = Import-Csv -Path $dataPath | + Select-Object Race,@{n="Date";e={[datetime]::ParseExact($_.date,"dd/MM/yyyy",(Get-Culture))}}, FinishPosition, Driver, GridPosition, Team,Points | + Group-Object -Property RACE $topRow = $lastDataRow = 1 + $results.Count $excel = $results[0].Group[0] | Export-Excel -Path $path -StartRow $TopRow -BoldTopRow -PassThru @@ -39,8 +41,16 @@ Describe "Creating small named ranges with hyperlinks" { $ct = New-ConditionalText -Text "Ferrari" $ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalText ([System.Drawing.Color]::Red) -Background ([System.Drawing.Color]::White) #Test new-conditionalText in shortest and longest forms. #Create links for each group name (race) and Export them so they start at Cell A1; create a pivot table with definition just created, save the file and open in Excel - $results | ForEach-Object {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} | #Test Exporting Hyperlinks with display property. - Export-Excel -ExcelPackage $excel -AutoSize -PivotTableDefinition $pt -Calculate -ConditionalFormat $ct,$ct2 #Test conditional text rules in conditional format (orignally icon sets only ) + $excel = $results | ForEach-Object {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} | #Test Exporting Hyperlinks with display property. + Export-Excel -ExcelPackage $excel -AutoSize -PivotTableDefinition $pt -Calculate -ConditionalFormat $ct,$ct2 -PassThru #Test conditional text rules in conditional format (orignally icon sets only ) + + $null = Add-WorkSheet -ExcelPackage $excel -WorksheetName "Points1" + Add-PivotTable -PivotTableName "Points1" -Address $excel.Points1.Cells["A1"] -ExcelPackage $excel -SourceWorkSheet sheet1 -SourceRange $excel.Sheet1.Tables[0].Address.Address -PivotRows Driver,Date -PivotData @{Points="SUM"} -GroupDateRow Date -GroupDatePart Years, Months + + $null = Add-WorkSheet -ExcelPackage $excel -WorksheetName "Places1" + $newpt = Add-PivotTable -PivotTableName "Places1" -Address $excel.Places1.Cells["A1"] -ExcelPackage $excel -SourceWorkSheet sheet1 -SourceRange $excel.Sheet1.Tables[0].Address.Address -PivotRows Driver,FinishPosition -PivotData @{Date="Count"} -GroupNumericRow FinishPosition -GroupNumbericMin 1 -GroupNumbericMax 25 -GroupNumbericInterval 3 -PassThru + $newpt.RowFields[0].SubTotalFunctions = [OfficeOpenXml.Table.PivotTable.eSubTotalFunctions]::None + Close-ExcelPackage -ExcelPackage $excel $excel = Open-ExcelPackage $path $sheet = $excel.Workbook.Worksheets[1] @@ -98,4 +108,32 @@ Describe "Creating small named ranges with hyperlinks" { $sheet.Tables[0].ShowRowStripes | should not be $true } } + Context "Adding Pivot tables" { + it "Added a worksheet with a pivot table grouped by date " { + $excel.Points1 | should not beNullOrEmpty + $excel.Points1.PivotTables.Count | should be 1 + $pt = $excel.Points1.PivotTables[0] + $pt.RowFields.Count | should be 3 + $pt.RowFields[0].name | should be "Driver" + $pt.RowFields[0].Grouping | should benullorEmpty + $pt.RowFields[1].name | should be "years" + $pt.RowFields[1].Grouping | should not benullorEmpty + $pt.RowFields[2].name | should be "date" + $pt.RowFields[2].Grouping | should not benullorEmpty + } + it "Added a worksheet with a pivot table grouped by Number " { + $excel.Places1 | should not beNullOrEmpty + $excel.Places1.PivotTables.Count | should be 1 + $pt = $excel.Places1.PivotTables[0] + $pt.RowFields.Count | should be 2 + $pt.RowFields[0].name | should be "Driver" + $pt.RowFields[0].Grouping | should benullorEmpty + $pt.RowFields[0].SubTotalFunctions.ToString() | should be "None" + $pt.RowFields[1].name | should be "FinishPosition" + $pt.RowFields[1].Grouping | should not benullorEmpty + $pt.RowFields[1].Grouping.Start | should be 1 + $pt.RowFields[1].Grouping.End | should be 25 + $pt.RowFields[1].Grouping.Interval | should be 3 + } + } } \ No newline at end of file From 6f3420d11e63936afa485eb1ae73f34e28e817bc Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 20:15:45 +0000 Subject: [PATCH 12/17] Revert "path fix" This reverts commit 234615dfdb0bb154041c03c6fdafd3b7cf05716b. --- DoTests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 2d2aa9d..801d3dc 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -15,7 +15,6 @@ $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | Fo if (!$DontCreateZip) { if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} - elseif (-not (test-path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -PathType Container)) {mkdir -path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -Verbose} $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) Compress-Archive -Path . -DestinationPath $dest -Verbose } From 01e3ea206d4e7bf8dbfc4a0110f880c821b06cbb Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 20:16:09 +0000 Subject: [PATCH 13/17] Revert "One more" This reverts commit 284560e1091a805fe9a5b530a5c26b42b7477a40. --- DoTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 801d3dc..8a21915 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -16,7 +16,7 @@ $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | Fo if (!$DontCreateZip) { if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) - Compress-Archive -Path . -DestinationPath $dest -Verbose + Compress-Archive -Path . -DestinationPath .\$dest -Verbose } if ($null -eq (Get-Module -ListAvailable pester)) { From 285e9e494987133d042c891470f922e5efafbabf Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 20:16:25 +0000 Subject: [PATCH 14/17] Revert "Update azure-pipelines.yml" This reverts commit eca631670c63956b5b3059ba417f99d4b69abed3. --- azure-pipelines.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d7f4cc9..dc2278b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -6,12 +6,7 @@ steps: - powershell: '.\DoTests.ps1' displayName: 'PowerShell Script' -- task: PublishBuildArtifacts@1 - inputs: - pathtoPublish: '$(Build.ArtifactStagingDirectory)' - artifactName: drop1 - trigger: paths: exclude: - - README.md + - README.md \ No newline at end of file From 787dda70ee6460ab348f282a83087417cd73721d Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 20:16:34 +0000 Subject: [PATCH 15/17] Revert "Take verbose back out of DoTests" This reverts commit 268d48ce3d947d2da7a5456b52bb1acd5b224572. --- DoTests.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 8a21915..9b9527a 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -9,6 +9,7 @@ param( $PSVersionTable.PSVersion $env:BUILD_ARTIFACTSTAGINGDIRECTORY +$VerbosePreference = "Continue" ## Create the zip before the tests run ## Otherwise the EPPlus.dll is in use after the Pester run $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | ForEach-Object ModuleVersion @@ -27,4 +28,4 @@ $result = Invoke-Pester -Script $PSScriptRoot\__tests__ -Verbose -PassThru if ($result.FailedCount -gt 0) { throw "$($result.FailedCount) tests failed." -} +} \ No newline at end of file From bef2f296517d4cc607b436e5be8a6397a8e1eaba Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 20:16:45 +0000 Subject: [PATCH 16/17] Revert "Update DoTests.ps1" This reverts commit c5cc018eb588b4465b4f363caf34db0544deea1b. --- DoTests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index 9b9527a..d17731a 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -3,7 +3,7 @@ param( ) ## -# Called by Azure Devops +# Used in Appveyor.yml ## $PSVersionTable.PSVersion From 72e44da2193ca5e3d134930f68ae830404f5c970 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Thu, 6 Dec 2018 21:38:13 +0000 Subject: [PATCH 17/17] Put back DoTests and yml file. Updated readme for pivot groups --- DoTests.ps1 | 9 +++------ README.md | 3 +++ azure-pipelines.yml | 5 ++++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/DoTests.ps1 b/DoTests.ps1 index d17731a..ce81979 100644 --- a/DoTests.ps1 +++ b/DoTests.ps1 @@ -7,21 +7,18 @@ param( ## $PSVersionTable.PSVersion -$env:BUILD_ARTIFACTSTAGINGDIRECTORY -$VerbosePreference = "Continue" ## Create the zip before the tests run ## Otherwise the EPPlus.dll is in use after the Pester run $ModuleVersion = (Get-Content -Raw .\ImportExcel.psd1) | Invoke-Expression | ForEach-Object ModuleVersion if (!$DontCreateZip) { - if ($null -eq $env:BUILD_ARTIFACTSTAGINGDIRECTORY) {$env:BUILD_ARTIFACTSTAGINGDIRECTORY = '.'} - $dest = Join-Path -Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY -ChildPath ("ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss")) - Compress-Archive -Path . -DestinationPath .\$dest -Verbose + $dest = "ImportExcel-{0}-{1}.zip" -f $ModuleVersion, (Get-Date).ToString("yyyyMMddHHmmss") + Compress-Archive -Path . -DestinationPath .\$dest } if ($null -eq (Get-Module -ListAvailable pester)) { - Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser -Verbose + Install-Module -Name Pester -Repository PSGallery -Force -Scope CurrentUser } $result = Invoke-Pester -Script $PSScriptRoot\__tests__ -Verbose -PassThru diff --git a/README.md b/README.md index 10fbc5d..976498e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,9 @@ Install-Module ImportExcel # What's new - Set-ExcelRow and Set-ExcelColumn now check that the worksheet name they passed exists in the workbook. +- Added parameters -GroupDateRow and -GroupDatePart & -GroupNumericRow, -GroupNumbericMin, -GroupNumbericMax and -GroupNumbericInterval + to Add-PivotTable and New-PivotTableDefinition. The date ones gather dates of the same year and/or quarter and/or month and/or day etc. + the number ones group numbers into bands, starting at Min, and going up steps specified by Interval. Added tests and help for these. # What's new 5.4 diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dc2278b..4665bdd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,9 +3,12 @@ resources: queue: name: Hosted VS2017 steps: -- powershell: '.\DoTests.ps1' +- powershell: ./ '.\DoTests.ps1' displayName: 'PowerShell Script' +- task: ArchiveFiles@2 + displayName: 'Archive $(Build.BinariesDirectory)' + trigger: paths: exclude: