From ef4ac9777b0f9f0da90835f4fbdf033c4a0e5f27 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Mon, 10 Sep 2018 14:26:29 +0100 Subject: [PATCH] Updates to examples . Minor bug fix to format in Merge-Multiple --- Examples/AddWorkSheet/AddWorkSheet.ps1 | 5 +- .../ConditionalFormatting/ConditionalText.ps1 | 10 +- .../ConditionalFormatting/ContainsBlanks.ps1 | 4 +- Examples/ConditionalFormatting/Databar.ps1 | 23 ++-- .../FormatCalculations.ps1 | 4 +- Examples/ConditionalFormatting/GetProcess.ps1 | 6 +- Examples/HyperLinks/First10Races.csv | 101 ++++++++++++++++++ Examples/HyperLinks/Races.ps1 | 27 +++++ .../Join-worksheet-blocks.sample.ps1 | 4 +- Examples/JoinWorksheet/JoinSalesData.ps1 | 3 +- .../Merge_2_Servers_Services.ps1 | 21 ++++ .../Merge_3_Servers_Services.ps1 | 34 ++++++ Examples/MoveSheets/MoveSheets.ps1 | 8 +- Examples/NumberFormat/ColorizeNumbers.ps1 | 4 +- Examples/NumberFormat/CurrencyFormat.ps1 | 7 +- Examples/PassThru/TryPassThru.ps1 | 10 +- Examples/PivotTable/PivotTableWithName.ps1 | 20 +++- Examples/PivotTable/TableAndPivotTable.ps1 | 26 +++++ .../PivotTableFilters/testPivotFilter.ps1 | 18 +++- .../SetColumnBackgroundColor.ps1 | 7 +- Examples/Tables/MultipleTables.ps1 | 15 +-- Export-Excel.ps1 | 10 +- Merge-worksheet.ps1 | 2 +- README.md | 19 ++-- .../Set-Row_Set-Column-SetFormat.tests.ps1 | 10 -- 25 files changed, 326 insertions(+), 72 deletions(-) create mode 100644 Examples/HyperLinks/First10Races.csv create mode 100644 Examples/HyperLinks/Races.ps1 create mode 100644 Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 create mode 100644 Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 create mode 100644 Examples/PivotTable/TableAndPivotTable.ps1 diff --git a/Examples/AddWorkSheet/AddWorkSheet.ps1 b/Examples/AddWorkSheet/AddWorkSheet.ps1 index a9120d0..4535d4c 100644 --- a/Examples/AddWorkSheet/AddWorkSheet.ps1 +++ b/Examples/AddWorkSheet/AddWorkSheet.ps1 @@ -4,8 +4,9 @@ $xlSourcefile = "$env:TEMP\Source.xlsx" Remove-Item $xlSourcefile -ErrorAction Ignore +#Put some simple data in a worksheet and Get an excel package object to represent the file $excel = 1..10 | Export-Excel $xlSourcefile -PassThru - +#Add a new worksheet named 'NewSheet' and copying the sheet that was just made (Sheet1) to the new sheet Add-WorkSheet -ExcelPackage $excel -WorkSheetname "NewSheet" -CopySource $excel.Workbook.Worksheets["Sheet1"] - +#Save and open in Excel Close-ExcelPackage -ExcelPackage $excel -Show diff --git a/Examples/ConditionalFormatting/ConditionalText.ps1 b/Examples/ConditionalFormatting/ConditionalText.ps1 index c04c297..96130e1 100644 --- a/Examples/ConditionalFormatting/ConditionalText.ps1 +++ b/Examples/ConditionalFormatting/ConditionalText.ps1 @@ -1,13 +1,13 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$file = ".\conditionalTextFormatting.xlsx" +$file = "$env:temp\conditionalTextFormatting.xlsx" Remove-Item $file -ErrorAction Ignore Get-Service | Select-Object Status, Name, DisplayName, ServiceName | Export-Excel $file -Show -AutoSize -AutoFilter -ConditionalText $( - New-ConditionalText stop - New-ConditionalText runn darkblue cyan - New-ConditionalText -ConditionalType EndsWith svc wheat green - New-ConditionalText -ConditionalType BeginsWith windows darkgreen wheat + New-ConditionalText stop #Stop is the condition value, the rule is defaults to 'Contains text' and the default Colors are used + New-ConditionalText runn darkblue cyan #runn is the condition value, the rule is defaults to 'Contains text'; the foregroundColur is darkblue and the background is cyan + New-ConditionalText -ConditionalType EndsWith svc wheat green #the rule here is 'Ends with' and the value is 'svc' the forground is wheat and the background dark green + New-ConditionalText -ConditionalType BeginsWith windows darkgreen wheat #this is 'Begins with "Windows"' the forground is dark green and the background wheat ) \ No newline at end of file diff --git a/Examples/ConditionalFormatting/ContainsBlanks.ps1 b/Examples/ConditionalFormatting/ContainsBlanks.ps1 index 83e01a4..45eb134 100644 --- a/Examples/ConditionalFormatting/ContainsBlanks.ps1 +++ b/Examples/ConditionalFormatting/ContainsBlanks.ps1 @@ -1,5 +1,6 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} +#Define a "Contains blanks" rule. No format is specified so it default to dark-red text on light-pink background. $ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks $data = $( @@ -11,7 +12,8 @@ $data = $( New-PSItem g h i ) -$file ="c:\temp\testblanks.xlsx" +$file ="$env:temp\testblanks.xlsx" Remove-Item $file -ErrorAction Ignore +#use the conditional format definition created above $data | Export-Excel $file -show -ConditionalText $ContainsBlanks \ No newline at end of file diff --git a/Examples/ConditionalFormatting/Databar.ps1 b/Examples/ConditionalFormatting/Databar.ps1 index 9a87f89..3b72742 100644 --- a/Examples/ConditionalFormatting/Databar.ps1 +++ b/Examples/ConditionalFormatting/Databar.ps1 @@ -1,23 +1,32 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -Remove-Item -Path .\test.xlsx -ErrorAction Ignore +$path = "$env:temp\test.xlsx" +Remove-Item -Path $path -ErrorAction Ignore +#Export processes, and get an ExcelPackage object representing the file. $excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | - Export-Excel -Path .\test.xlsx -ClearSheet -WorkSheetname "Processes" -PassThru + Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -PassThru $sheet = $excel.Workbook.Worksheets["Processes"] -$sheet.Column(1) | Set-Format -Bold -AutoFit + +#Apply fixed formatting to columns. Set-Format is an Alias for Set-Excel Range, -NFormat is an alias for numberformat +$sheet.Column(1) | Set-ExcelRange -Bold -AutoFit $sheet.Column(2) | Set-Format -Width 29 -WrapText $sheet.Column(3) | Set-Format -HorizontalAlignment Right -NFormat "#,###" -Set-Format -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###" -Set-Format -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold +Set-ExcelRange -Range -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###" +#Set-Format is an alias for Set-ExcelRange +Set-Format -Range $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold +#In Set-ExcelRange / Set-Format "-Address" is an alias for "-Range" Set-Format -Address $sheet.Row(1) -Bold -HorizontalAlignment Center -Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor Red -Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red +#Create a Red Data-bar for the values in Column D +Add-ConditionalFormatting -WorkSheet $sheet -Address "D2:D1048576" -DataBarColor Red +# Conditional formatting applies to "Addreses" aliases allow either "Range" or "Address" to be used in Set-ExcelRange or Add-Conditional formatting. +Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red foreach ($c in 5..9) {Set-Format -Address $sheet.Column($c) -AutoFit } +#Create a pivot and save the file. Export-Excel -ExcelPackage $excel -WorkSheetname "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show \ No newline at end of file diff --git a/Examples/ConditionalFormatting/FormatCalculations.ps1 b/Examples/ConditionalFormatting/FormatCalculations.ps1 index f2d271b..11098d7 100644 --- a/Examples/ConditionalFormatting/FormatCalculations.ps1 +++ b/Examples/ConditionalFormatting/FormatCalculations.ps1 @@ -1,6 +1,6 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$f = ".\testExport.xlsx" +$f = "$env:TEMP\testExport.xlsx" Remove-Item $f -ErrorAction Ignore @@ -21,6 +21,8 @@ $data = $( New-PSItem Westerly 120 New-PSItem SouthWest 118 ) +# in this example instead of doing $variable = New-Conditional text .... ; Export-excel -conditionalText $variable +# the syntax is used is Export-excel -conditionalText (New-Conditional text ) #$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage) diff --git a/Examples/ConditionalFormatting/GetProcess.ps1 b/Examples/ConditionalFormatting/GetProcess.ps1 index 773c490..ed6c47e 100644 --- a/Examples/ConditionalFormatting/GetProcess.ps1 +++ b/Examples/ConditionalFormatting/GetProcess.ps1 @@ -1,10 +1,12 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -Remove-Item .\testExport.xlsx -ErrorAction Ignore +Remove-Item "$env:TEMP\testExport.xlsx" -ErrorAction Ignore Get-Process | Where-Object Company | Select-Object Company, Name, PM, Handles, *mem* | - Export-Excel .\testExport.xlsx -Show -AutoSize -AutoNameRange ` +#This example creates a 3 Icon set for the values in the "PM column, and Highlights company names (anywhere in the data) with different colors + + Export-Excel "$env:TEMP\testExport.xlsx" -Show -AutoSize -AutoNameRange ` -ConditionalFormat $( New-ConditionalFormattingIconSet -Range "C:C" ` -ConditionalFormat ThreeIconSet -IconType Arrows diff --git a/Examples/HyperLinks/First10Races.csv b/Examples/HyperLinks/First10Races.csv new file mode 100644 index 0000000..46b3180 --- /dev/null +++ b/Examples/HyperLinks/First10Races.csv @@ -0,0 +1,101 @@ +Race,Date,FinishPosition,Driver,GridPosition,Team,Points +Australian,25/03/2018,1,Sebastian Vettel,3,Ferrari,25 +Australian,25/03/2018,2,Lewis Hamilton,1,Mercedes,18 +Australian,25/03/2018,3,Kimi Räikkönen,2,Ferrari,15 +Australian,25/03/2018,4,Daniel Ricciardo,8,Red Bull Racing-TAG Heuer,12 +Australian,25/03/2018,5,Fernando Alonso,10,McLaren-Renault,10 +Australian,25/03/2018,6,Max Verstappen,4,Red Bull Racing-TAG Heuer,8 +Australian,25/03/2018,7,Nico Hülkenberg,7,Renault,6 +Australian,25/03/2018,8,Valtteri Bottas,15,Mercedes,4 +Australian,25/03/2018,9,Stoffel Vandoorne,11,McLaren-Renault,2 +Australian,25/03/2018,10,Carlos Sainz,9,Renault,1 +Bahrain,08/04/2018,1,Sebastian Vettel,1,Ferrari,25 +Bahrain,08/04/2018,2,Valtteri Bottas,3,Mercedes,18 +Bahrain,08/04/2018,3,Lewis Hamilton,9,Mercedes,15 +Bahrain,08/04/2018,4,Pierre Gasly,5,STR-Honda,12 +Bahrain,08/04/2018,5,Kevin Magnussen,6,Haas-Ferrari,10 +Bahrain,08/04/2018,6,Nico Hülkenberg,7,Renault,8 +Bahrain,08/04/2018,7,Fernando Alonso,13,McLaren-Renault,6 +Bahrain,08/04/2018,8,Stoffel Vandoorne,14,McLaren-Renault,4 +Bahrain,08/04/2018,9,Marcus Ericsson,17,Sauber-Ferrari,2 +Bahrain,08/04/2018,10,Esteban Ocon,8,Force India-Mercedes,1 +Chinese,15/04/2018,1,Daniel Ricciardo,6,Red Bull Racing-TAG Heuer,25 +Chinese,15/04/2018,2,Valtteri Bottas,3,Mercedes,18 +Chinese,15/04/2018,3,Kimi Räikkönen,2,Ferrari,15 +Chinese,15/04/2018,4,Lewis Hamilton,4,Mercedes,12 +Chinese,15/04/2018,5,Max Verstappen,5,Red Bull Racing-TAG Heuer,10 +Chinese,15/04/2018,6,Nico Hülkenberg,7,Renault,8 +Chinese,15/04/2018,7,Fernando Alonso,13,McLaren-Renault,6 +Chinese,15/04/2018,8,Sebastian Vettel,1,Ferrari,4 +Chinese,15/04/2018,9,Carlos Sainz,9,Renault,2 +Chinese,15/04/2018,10,Kevin Magnussen,11,Haas-Ferrari,1 +Azerbaijan,29/04/2018,1,Lewis Hamilton,2,Mercedes,25 +Azerbaijan,29/04/2018,2,Kimi Räikkönen,6,Ferrari,18 +Azerbaijan,29/04/2018,3,Sergio Pérez,8,Force India-Mercedes,15 +Azerbaijan,29/04/2018,4,Sebastian Vettel,1,Ferrari,12 +Azerbaijan,29/04/2018,5,Carlos Sainz,9,Renault,10 +Azerbaijan,29/04/2018,6,Charles Leclerc,13,Sauber-Ferrari,8 +Azerbaijan,29/04/2018,7,Fernando Alonso,12,McLaren-Renault,6 +Azerbaijan,29/04/2018,8,Lance Stroll,10,Williams-Mercedes,4 +Azerbaijan,29/04/2018,9,Stoffel Vandoorne,16,McLaren-Renault,2 +Azerbaijan,29/04/2018,10,Brendon Hartley,19,STR-Honda,1 +Spanish,13/05/2018,1,Lewis Hamilton,1,Mercedes,25 +Spanish,13/05/2018,2,Valtteri Bottas,2,Mercedes,18 +Spanish,13/05/2018,3,Max Verstappen,5,Red Bull Racing-TAG Heuer,15 +Spanish,13/05/2018,4,Sebastian Vettel,3,Ferrari,12 +Spanish,13/05/2018,5,Daniel Ricciardo,6,Red Bull Racing-TAG Heuer,10 +Spanish,13/05/2018,6,Kevin Magnussen,7,Haas-Ferrari,8 +Spanish,13/05/2018,7,Carlos Sainz,9,Renault,6 +Spanish,13/05/2018,8,Fernando Alonso,8,McLaren-Renault,4 +Spanish,13/05/2018,9,Sergio Pérez,15,Force India-Mercedes,2 +Spanish,13/05/2018,10,Charles Leclerc,14,Sauber-Ferrari,1 +Monaco,27/05/2018,1,Daniel Ricciardo,1,Red Bull Racing-TAG Heuer,25 +Monaco,27/05/2018,2,Sebastian Vettel,2,Ferrari,18 +Monaco,27/05/2018,3,Lewis Hamilton,3,Mercedes,15 +Monaco,27/05/2018,4,Kimi Räikkönen,4,Ferrari,12 +Monaco,27/05/2018,5,Valtteri Bottas,5,Mercedes,10 +Monaco,27/05/2018,6,Esteban Ocon,6,Force India-Mercedes,8 +Monaco,27/05/2018,7,Pierre Gasly,10,STR-Honda,6 +Monaco,27/05/2018,8,Nico Hülkenberg,11,Renault,4 +Monaco,27/05/2018,9,Max Verstappen,20,Red Bull Racing-TAG Heuer,2 +Monaco,27/05/2018,10,Carlos Sainz,8,Renault,1 +Canadian,10/06/2018,1,Sebastian Vettel,1,Ferrari,25 +Canadian,10/06/2018,2,Valtteri Bottas,2,Mercedes,18 +Canadian,10/06/2018,3,Max Verstappen,3,Red Bull Racing-TAG Heuer,15 +Canadian,10/06/2018,4,Daniel Ricciardo,6,Red Bull Racing-TAG Heuer,12 +Canadian,10/06/2018,5,Lewis Hamilton,4,Mercedes,10 +Canadian,10/06/2018,6,Kimi Räikkönen,5,Ferrari,8 +Canadian,10/06/2018,7,Nico Hülkenberg,7,Renault,6 +Canadian,10/06/2018,8,Carlos Sainz,9,Renault,4 +Canadian,10/06/2018,9,Esteban Ocon,8,Force India-Mercedes,2 +Canadian,10/06/2018,10,Charles Leclerc,13,Sauber-Ferrari,1 +French,24/06/2018,1,Lewis Hamilton,1,Mercedes,25 +French,24/06/2018,2,Max Verstappen,4,Red Bull Racing-TAG Heuer,18 +French,24/06/2018,3,Kimi Räikkönen,6,Ferrari,15 +French,24/06/2018,4,Daniel Ricciardo,5,Red Bull Racing-TAG Heuer,12 +French,24/06/2018,5,Sebastian Vettel,3,Ferrari,10 +French,24/06/2018,6,Kevin Magnussen,9,Haas-Ferrari,8 +French,24/06/2018,7,Valtteri Bottas,2,Mercedes,6 +French,24/06/2018,8,Carlos Sainz,7,Renault,4 +French,24/06/2018,9,Nico Hülkenberg,12,Renault,2 +French,24/06/2018,10,Charles Leclerc,8,Sauber-Ferrari,1 +Austrian,01/07/2018,1,Max Verstappen,4,Red Bull Racing-TAG Heuer,25 +Austrian,01/07/2018,2,Kimi Räikkönen,3,Ferrari,18 +Austrian,01/07/2018,3,Sebastian Vettel,6,Ferrari,15 +Austrian,01/07/2018,4,Romain Grosjean,5,Haas-Ferrari,12 +Austrian,01/07/2018,5,Kevin Magnussen,8,Haas-Ferrari,10 +Austrian,01/07/2018,6,Esteban Ocon,11,Force India-Mercedes,8 +Austrian,01/07/2018,7,Sergio Pérez,15,Force India-Mercedes,6 +Austrian,01/07/2018,8,Fernando Alonso,20,McLaren-Renault,4 +Austrian,01/07/2018,9,Charles Leclerc,17,Sauber-Ferrari,2 +Austrian,01/07/2018,10,Marcus Ericsson,18,Sauber-Ferrari,1 +British,08/07/2018,1,Sebastian Vettel,2,Ferrari,25 +British,08/07/2018,2,Lewis Hamilton,1,Mercedes,18 +British,08/07/2018,3,Kimi Räikkönen,3,Ferrari,15 +British,08/07/2018,4,Valtteri Bottas,4,Mercedes,12 +British,08/07/2018,5,Daniel Ricciardo,6,Red Bull Racing-TAG Heuer,10 +British,08/07/2018,6,Nico Hülkenberg,11,Renault,8 +British,08/07/2018,7,Esteban Ocon,10,Force India-Mercedes,6 +British,08/07/2018,8,Fernando Alonso,13,McLaren-Renault,4 +British,08/07/2018,9,Kevin Magnussen,7,Haas-Ferrari,2 +British,08/07/2018,10,Sergio Pérez,12,Force India-Mercedes,1 \ No newline at end of file diff --git a/Examples/HyperLinks/Races.ps1 b/Examples/HyperLinks/Races.ps1 new file mode 100644 index 0000000..fefe945 --- /dev/null +++ b/Examples/HyperLinks/Races.ps1 @@ -0,0 +1,27 @@ + +#First 10 races is a CSV file containing the top 10 finishers for the first 10 Formula one races of 2018. Read this file and group the results by race +#We will create links to each race in the first 10 rows of the spreadSheet +#The next row will be column labels +#After that will come a block for each race. + +#Read the data, and decide how much space to leave for the hyperlinks +$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent +$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.csv" +$results = Import-Csv -Path $dataPath | Group-Object -Property RACE +$topRow = $lastDataRow = 1 + $results.Count + +#Export the first row of the first group (race) with headers. +$path = "$env:TEMP\Results.xlsx" +Remove-Item -Path $path -ErrorAction SilentlyContinue +$excel = $results[0].Group[0] | Export-Excel -Path $path -StartRow $TopRow -BoldTopRow -PassThru + +#export each group (race) below the last one, without headers, and create a range for each using the group (Race) name +foreach ($r in $results) { + $excel = $R.Group | Export-Excel -ExcelPackage $excel -NoHeader -StartRow ($lastDataRow +1) -RangeName $R.Name -PassThru -AutoSize + $lastDataRow += $R.Group.Count +} + +#Create a hyperlink for each property with display text of "RaceNameGP" which links to the range created when the rows were exported a +$results | ForEach-Object {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} | + Export-Excel -ExcelPackage $excel -AutoSize -Show + diff --git a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 index 5ee0506..b19fcdb 100644 --- a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 +++ b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 @@ -1,11 +1,13 @@ $path = "$env:TEMP\Test.xlsx" Remove-item -Path $path -ErrorAction SilentlyContinue - Get-WmiObject -Class win32_logicaldisk | +#Export disk volume, and Network adapter to their own sheets. +Get-WmiObject -Class win32_logicaldisk | Select-Object -Property DeviceId,VolumeName, Size,Freespace | Export-Excel -Path $path -WorkSheetname Volumes -NumberFormat "0,000" Get-NetAdapter | Select-Object -Property Name,InterfaceDescription,MacAddress,LinkSpeed | Export-Excel -Path $path -WorkSheetname NetAdapters +#Create a summary page with a title of Summary, label the blocks with the name of the sheet they came from and hide the source sheets Join-Worksheet -Path $path -HideSource -WorkSheetName Summary -NoHeader -LabelBlocks -AutoSize -Title "Summary" -TitleBold -TitleSize 22 -show diff --git a/Examples/JoinWorksheet/JoinSalesData.ps1 b/Examples/JoinWorksheet/JoinSalesData.ps1 index a094ffd..f8938f1 100644 --- a/Examples/JoinWorksheet/JoinSalesData.ps1 +++ b/Examples/JoinWorksheet/JoinSalesData.ps1 @@ -11,12 +11,13 @@ $params = @{ ExcelChartDefinition = New-ExcelChartDefinition -XRange Item -YRange UnitSold -Title 'Units Sold' Path = $xlfile } - +#Import 4 sets of sales data from 4 CSV files, using the parameters above. Import-Csv $PSScriptRoot\NorthSales.csv | Export-Excel -WorkSheetname North @params Import-Csv $PSScriptRoot\EastSales.csv | Export-Excel -WorkSheetname East @params Import-Csv $PSScriptRoot\SouthSales.csv | Export-Excel -WorkSheetname South @params Import-Csv $PSScriptRoot\WestSales.csv | Export-Excel -WorkSheetname West @params +#Join the 4 worksheets together on a sheet named Allsales, use the same parameters, except for AutoNameRange and ExcelChartDefinition. $params.Remove("AutoNameRange") $params.Remove("ExcelChartDefinition") Join-Worksheet -WorkSheetName AllSales -Show @params \ No newline at end of file diff --git a/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 b/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 new file mode 100644 index 0000000..d6c7b29 --- /dev/null +++ b/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 @@ -0,0 +1,21 @@ +Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue + +#Get a subset of services into $s and export them +[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property * +$s | Export-Excel -Path $env:temp\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. +#Change a row. Add a row. Delete a row. And export the changed $s to a second file. +$s[2].DisplayName = "Changed from the orginal" #This will be row 4 in Excel - this should be highlighted as a change + +$d = $s[-1] | Select-Object -Property * +$d.DisplayName = "Dummy Service" +$d.Name = "Dummy" +$s.Insert(3,$d) #This will be row 5 in Excel - this should be highlighted as a new item + +$s.RemoveAt(5) #This will be row 7 in Excel - this should be highlighted as deleted item + +$s | Export-Excel -Path $env:temp\server2.xlsx + +#This use of Merge-worksheet Assumes a default worksheet name, (sheet1) We will check and output Name (the key), DisplayName and StartType and ignore other properties. +Merge-Worksheet -Referencefile "$env:temp\server1.xlsx" -Differencefile "$env:temp\Server2.xlsx" -OutputFile "$env:temp\combined1.xlsx" -Property name,displayname,startType -Key name -Show \ No newline at end of file diff --git a/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 b/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 new file mode 100644 index 0000000..fec6917 --- /dev/null +++ b/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 @@ -0,0 +1,34 @@ +Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue + +#Get a subset of services into $s and export them +[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name,DisplayName,StartType +$s | Export-Excel -Path $env:temp\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. +#Change a row. Add a row. Delete a row. And export the changed $s to a second file. +$row4Displayname = $s[2].DisplayName +$s[2].DisplayName = "Changed from the orginal" #This will be excel row 4 and Server 2 will show as changed. + +$d = $s[-1] | Select-Object -Property * +$d.DisplayName = "Dummy Service" +$d.Name = "Dummy" +$s.Insert(3,$d) #This will be Excel row 5 and server 2 will show as changed - so will Server 3 + +$s.RemoveAt(5) #This will be Excel row 7 and Server 2 will show as missing. + +$s | Export-Excel -Path $env:temp\server2.xlsx + +#Make some more changes to $s and export it to a third file +$s[2].displayname = $row4Displayname #Server 3 row 4 will match server 1 so won't be highlighted + +$d = $s[-1] | Select-Object -Property * +$d.DisplayName = "Second Service" +$d.Name = "Service2" +$s.Insert(6,$d) #This will be an extra row in Server 3 at row 8. It will show as missing in Server 2. +$s.RemoveAt(8) #This will show as missing in Server 3 at row 11 () + +$s | Export-Excel -Path $env:temp\server3.xlsx + +#Now bring the three files together. + +Merge-MultipleSheets -Path "$env:temp\server1.xlsx", "$env:temp\Server2.xlsx","$env:temp\Server3.xlsx" -OutputFile "$env:temp\combined3.xlsx" -Property name,displayname,startType -Key name -Show \ No newline at end of file diff --git a/Examples/MoveSheets/MoveSheets.ps1 b/Examples/MoveSheets/MoveSheets.ps1 index b5723f4..6b6887b 100644 --- a/Examples/MoveSheets/MoveSheets.ps1 +++ b/Examples/MoveSheets/MoveSheets.ps1 @@ -3,7 +3,7 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} $xlfile = "$env:TEMP\testThis.xlsx" Remove-Item $xlfile -ErrorAction Ignore -1..10 | Export-Excel $xlfile -WorkSheetname First -11..20 | Export-Excel $xlfile -WorkSheetname Second -MoveToStart -21..30 | Export-Excel $xlfile -WorkSheetname Third -MoveBefore First -31..40 | Export-Excel $xlfile -WorkSheetname Fourth -MoveAfter Third -Show \ No newline at end of file +1..10 | Export-Excel $xlfile -WorkSheetname First #'First' will be the only sheet +11..20 | Export-Excel $xlfile -WorkSheetname Second -MoveToStart #'Second' is moved before first so the order is 'Second', 'First' +21..30 | Export-Excel $xlfile -WorkSheetname Third -MoveBefore First #'Second' is moved before first so the order is 'Second', 'Third', 'First' +31..40 | Export-Excel $xlfile -WorkSheetname Fourth -MoveAfter Third -Show #'Fourth' is moved after third so the order is ' 'Second', 'Third', 'Fourth' First' \ No newline at end of file diff --git a/Examples/NumberFormat/ColorizeNumbers.ps1 b/Examples/NumberFormat/ColorizeNumbers.ps1 index 18a2dc1..1352432 100644 --- a/Examples/NumberFormat/ColorizeNumbers.ps1 +++ b/Examples/NumberFormat/ColorizeNumbers.ps1 @@ -1,6 +1,6 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$file = "disks.xlsx" +$file = "$env:TEMP\disks.xlsx" Remove-Item $file -ErrorAction Ignore @@ -11,5 +11,5 @@ $data = $( New-PSItem -3.2 -4.1 New-PSItem -5.2 6.1 ) - +#Set the numbers throughout the sheet to format as positive in blue with a + sign, negative in Red with a - sign. $data | Export-Excel -Path $file -Show -AutoSize -NumberFormat "[Blue]+0.#0;[Red]-0.#0" diff --git a/Examples/NumberFormat/CurrencyFormat.ps1 b/Examples/NumberFormat/CurrencyFormat.ps1 index e7c327a..d6f589d 100644 --- a/Examples/NumberFormat/CurrencyFormat.ps1 +++ b/Examples/NumberFormat/CurrencyFormat.ps1 @@ -1,6 +1,6 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$file = "disks.xlsx" +$file = "$env:temp\disks.xlsx" Remove-Item $file -ErrorAction Ignore @@ -12,6 +12,5 @@ $data = $( New-PSItem -5.2 6.1 New-PSItem 1000 -2000 ) - -$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat '[Blue]$#,##0.00;[Red]-$#,##0.00' - +#Number format can expand terms like Currency, to the local currency format +$data | Export-Excel -Path $file -Show -AutoSize -NumberFormat 'Currency' diff --git a/Examples/PassThru/TryPassThru.ps1 b/Examples/PassThru/TryPassThru.ps1 index c33060f..a80e176 100644 --- a/Examples/PassThru/TryPassThru.ps1 +++ b/Examples/PassThru/TryPassThru.ps1 @@ -1,16 +1,20 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$file = "sales.xlsx" +$file = "$env:Temp\sales.xlsx" Remove-Item $file -ErrorAction Ignore +#Using -Passthru with Export-Excel returns an Excel Package object. $xlPkg = Import-Csv .\sales.csv | Export-Excel $file -PassThru -$ws = $xlPkg.Workbook.WorkSheets[1] +#We add script properties to the package so $xlPkg.Sheet1 is equivalent to $xlPkg.Workbook.WorkSheets["Sheet1"] +$ws = $xlPkg.Sheet1 +#We can manipulate the cells ... $ws.Cells["E1"].Value = "TotalSold" $ws.Cells["F1"].Value = "Add 10%" +#This is for illustration - there are more efficient ways to do this. 2..($ws.Dimension.Rows) | ForEach-Object { $ws.Cells["E$_"].Formula = "=C$_+D$_" @@ -19,7 +23,7 @@ $ws.Cells["F1"].Value = "Add 10%" $ws.Cells.AutoFitColumns() +#You can call close-ExcelPackage $xlPkg -show, but here we will do the ssteps explicitly $xlPkg.Save() $xlPkg.Dispose() - Invoke-Item $file \ No newline at end of file diff --git a/Examples/PivotTable/PivotTableWithName.ps1 b/Examples/PivotTable/PivotTableWithName.ps1 index 45524ea..ae0c395 100644 --- a/Examples/PivotTable/PivotTableWithName.ps1 +++ b/Examples/PivotTable/PivotTableWithName.ps1 @@ -1,15 +1,25 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -Remove-Item .\test1.xlsx -ErrorAction Ignore - $ExcelParams = @{ - Path = ".\test1.xlsx" + Path = "$env:TEMP\test1.xlsx" IncludePivotTable = $true PivotRows = 'Company' PivotTableName = 'MyTable' PivotData = @{'Handles' = 'sum'} Show = $true + Activate = $true } +Remove-Item $ExcelParams.Path -ErrorAction Ignore +Get-Process | Select-Object Company, Handles | Export-Excel @ExcelParams -Get-Process | Select-Object Company, Handles | - Export-Excel @ExcelParams \ No newline at end of file +<# Builds a pivot table that looks like this: + + Sum of Handles + Row Labels Total + Adobe Systems Incorporated 3100 + (blank) 214374 + Apple Inc. 215 + etc + etc + Grand Total 365625 +#> \ No newline at end of file diff --git a/Examples/PivotTable/TableAndPivotTable.ps1 b/Examples/PivotTable/TableAndPivotTable.ps1 new file mode 100644 index 0000000..0d5c0dc --- /dev/null +++ b/Examples/PivotTable/TableAndPivotTable.ps1 @@ -0,0 +1,26 @@ +$path = "$Env:TEMP\test.xlsx" +remove-item -path $path -ErrorAction SilentlyContinue + +#Export some sales data to Excel, format it as a table and put a data-bar in + +$excel = ConvertFrom-Csv @" +Product, City, Gross, Net +Apple, London , 300, 250 +Orange, London , 400, 350 +Banana, London , 300, 200 +Orange, Paris, 600, 500 +Banana, Paris, 300, 200 +Apple, New York, 1200,700 +"@ | Export-Excel -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor="Green"} -PassThru + +#Add a pivot table on the same sheet, using this data. set the table style and number format. Use the "City" as row names, and "Product" for columnnames, and total both the gross and net columns +#Add a pivot chart (defined in a hash table) +Add-PivotTable -Address $excel.Sheet1.Cells["F1"] -SourceWorkSheet $Excel.Sheet1 -SourceRange $Excel.Sheet1.Dimension.Address -PivotTableName "Sales" -PivotTableSyle "Medium12" -Activate ` + -PivotRows "City" -PivotColumns "Product" -PivotData @{Gross="Sum";Net="Sum"} -PivotNumberFormat "$#,##0.00" -PivotTotals "Both" -PivotChartDefinition @{ + Title="Gross and net by city and product"; + ChartType="ColumnClustered"; + Column=11; Width=500; Height=360; + YMajorUnit=500; YMinorUnit=100; YAxisNumberformat="$#,##0" + LegendPostion="Bottom"} +#Save and open in excel +Close-ExcelPackage $excel -Show \ No newline at end of file diff --git a/Examples/PivotTableFilters/testPivotFilter.ps1 b/Examples/PivotTableFilters/testPivotFilter.ps1 index b112690..33b89fd 100644 --- a/Examples/PivotTableFilters/testPivotFilter.ps1 +++ b/Examples/PivotTableFilters/testPivotFilter.ps1 @@ -1,6 +1,6 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$xlFile=".\testPivot.xlsx" +$xlFile="$env:TEMP\testPivot.xlsx" Remove-Item $xlFile -ErrorAction Ignore $data =@" @@ -18,4 +18,18 @@ $data | -AutoSize -AutoFilter ` -IncludePivotTable ` -PivotRows Product ` - -PivotData @{"Units"="sum"} -PivotFilter Region, Area + -PivotData @{"Units"="sum"} -PivotFilter Region, Area -Activate + +<# +Creates a Pivot table that looks like +Region All^ +Area All^ + +Sum of Units +Row Labels Total +Apple 100 +Pear 240 +Grape 280 +Banana 160 +Grand Total 780 +#> \ No newline at end of file diff --git a/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 b/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 index 47c416e..36580c1 100644 --- a/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 +++ b/Examples/SetColumnBackgroundColor/SetColumnBackgroundColor.ps1 @@ -1,10 +1,13 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$p = Get-Process | Select-Object Company, Handles | Export-Excel c:\temp\testBackgroundColor.xlsx -ClearSheet -KillExcel -PassThru +$path = "$env:TEMP\testBackgroundColor.xlsx" + +$p = Get-Process | Select-Object Company, Handles | Export-Excel $path -ClearSheet -PassThru $ws = $p.Workbook.WorkSheets[1] $totalRows = $ws.Dimension.Rows -Set-Format -Address $ws.Cells["B2:B$($totalRows)"] -BackgroundColor LightBlue +#Set the range from B2 to the last active row. s +Set-ExcelRange -Range $ws.Cells["B2:B$($totalRows)"] -BackgroundColor LightBlue Export-Excel -ExcelPackage $p -show -AutoSize \ No newline at end of file diff --git a/Examples/Tables/MultipleTables.ps1 b/Examples/Tables/MultipleTables.ps1 index 86d8752..03f8a89 100644 --- a/Examples/Tables/MultipleTables.ps1 +++ b/Examples/Tables/MultipleTables.ps1 @@ -1,7 +1,7 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {} -$xlfile = "testData.xlsx" -Remove-Item *.xlsx +$xlfile = "$env:Temp\testData.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue $r = Get-ChildItem C:\WINDOWS\system32 @@ -23,16 +23,19 @@ $top10ByFileSize = $r | Select-Object -First 10 Name, @{n="Size";e={$_.Length}} #,Extension,Path -$top10BySize | Export-Excel $xlfile -WorkSheetname FileInfo -TableName ExtSize -$top10ByCount | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 13 -TableName ExtCount -$top10ByFileSize | Export-Excel $xlfile -WorkSheetname FileInfo -StartRow 25 -AutoSize -TableName FileSize +$xlPkg = $top10BySize | Export-Excel -path $xlfile -WorkSheetname FileInfo -TableName ExtSize -PassThru +$xlPkg = $top10ByCount | Export-Excel -ExcelPackage $xlPkg -WorkSheetname FileInfo -StartRow 13 -TableName ExtCount -PassThru +$xlPkg = $top10ByFileSize | Export-Excel -ExcelPackage $xlPkg -WorkSheetname FileInfo -StartRow 25 -TableName FileSize -PassThru -AutoSize + +#worksheets.tables["Name1","Name2"] returns 2 tables. Set-ExcelRange can process those and will set the number format over both +Set-ExcelRange -Range $xlpkg.Workbook.Worksheets[1].Tables["ExtSize","FileSize"] -NumberFormat '0,,"MB"' $ps = Get-Process | Where-Object Company $ps | Sort-Object handles -Descending | Select-Object -First 10 company, handles | - Export-Excel $xlfile -WorkSheetname Handles -AutoSize -TableName Handles + Export-Excel -ExcelPackage $xlPkg -WorkSheetname Handles -AutoSize -TableName Handles $ps | Sort-Object PM -Descending | diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 2bd5767..a768737 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -1049,15 +1049,17 @@ function Add-WorkSheet { made the default sheet when excel opens if -Activate is specified. .Example $WorksheetActors = $ExcelPackage | Add-WorkSheet -WorkSheetname Actors + $ExcelPackage holds an Excel package object (returned by Open-ExcelPackage, or Export-Excel -passthru). - This command will add a sheet named actors, or return the sheet if it exists, and stores the result in $WorkSheetActors + This command will add a sheet named 'Actors', or return the sheet if it exists, and the result is stored in $WorkSheetActors. .Example $WorksheetActors = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname "Actors" -ClearSheet -MoveToStart - This time the Excel package object is passed as a parameter instead of piped. If the Actors sheet already exists it is deleted - and re-created. The new sheet will be created last in the workbook, and -MoveToStart Moves it to the start + + This time the Excel package object is passed as a parameter instead of piped. If the 'Actors' sheet already exists it is deleted + and re-created. The new sheet will be created last in the workbook, and -MoveToStart Moves it to the start. .Example $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationName -CopySource $sourceWs -Activate - This time the workbook is used instead of the package, and a worksheet is copied - $SourceWs is a worksheet object, it can come + This time a workbook is used instead of a package, and a worksheet is copied - $SourceWs is a worksheet object, which can come from the same workbook or a different one. Here the new copy of the data is made the active sheet when the workbook is opened. #> [cmdletBinding()] diff --git a/Merge-worksheet.ps1 b/Merge-worksheet.ps1 index 209db04..ede7351 100644 --- a/Merge-worksheet.ps1 +++ b/Merge-worksheet.ps1 @@ -434,7 +434,7 @@ Function Merge-MultipleSheets { $columnNo = $cell.start.Column -1 $cellAddr = [OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R1C$columnNo",1,$columnNo) while ($sheet.cells[$cellAddr].value -match $prefix) { - $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='None'; WorkSheet=$sheet; Range=$([OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[1]C[$columnNo]:R[1048576]C[$columnNo]",0,0)) } + $condFormattingParams = @{RuleType='Expression'; BackgroundPattern='Solid'; WorkSheet=$sheet; Range=$([OfficeOpenXml.ExcelAddress]::TranslateFromR1C1("R[1]C[$columnNo]:R[1048576]C[$columnNo]",0,0)) } Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Added"' ) -BackgroundColor $AddBackgroundColor Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Changed"') -BackgroundColor $ChangeBackgroundColor Add-ConditionalFormatting @condFormattingParams -ConditionValue ($cell.Address + '="Removed"') -BackgroundColor $DeleteBackgroundColor diff --git a/README.md b/README.md index 8dd3480..d05e6ab 100644 --- a/README.md +++ b/README.md @@ -51,19 +51,20 @@ Install-Module ImportExcel -scope CurrentUser ```PowerShell Install-Module ImportExcel ``` -- Lots of help improvements and some tidying up of examples -- Open-Excel Package and Add-Worksheet now add worksheets as script properties so if you do $Excel = open-excelpackage -path test.xlsx ; $excel.sheet1 ; it will return the sheet named sheet 1 Excel.sheetName is a script property which returns $this.workbook.worksheets["Sheetname"] -- Renamed Set-Column to Set-ExcelColum, Set-Row to Set-ExcelRow, and Set-Format, to Set-ExcelRange. Added aliases so the old names still work -- Set-ExcelRange (or set-Format) used "Address" and "Range" incorrectly. There is now a single parameter "Range", with an alias of "Address" and the code beneath ensures that the function accepts a string specifying cells ("A1:Z10") or a range name; and worksheet. OR A named range, Or Table, or a tables's address, or part of the worksheet.cells collection. -- `Add-ConditionalFormatting`: Used "address" correctly, and it will accept ranges in the address parameter (range is now an alias for address). It now wraps conditional value strings in quotes when needed (for = <= >= string needs to be in double quotes). Parameter intellisense has been improved. There are new parameters: -StopIfTrue and -Priority and support for using the -Reverse parameter with Color-scale rules. Booleans in the sheet are now supported as the value for a condition. Also brought the two different kinds of condition together inside export-excel, and fixed a bug where named-ranges didn't work in some places. In `New-ConditionalText`, more types of conditional format are supported, and -ConditionalTextColor now has an argument completer -- Improved handling of hyperlinks in `Export-Excel`. +- Help improvements and tidying up of examples and extra examples +- Open-Excel Package and Add-Worksheet now add worksheets as script properties so `$Excel = Open-ExcelPackage -path test.xlsx ; $excel.sheet1` will return the sheet named "sheet1" `$Excel.SheetName` is a script property which is defined as `$this.workbook.worksheets["Sheetname"]` +- Renamed Set-Column to `Set-ExcelColumn`, Set-Row to `Set-ExcelRow`, and Set-Format, to `Set-ExcelRange`. Added aliases so the old names still work. +- `Set-ExcelRange` (or set-Format) used "Address" and "Range" incorrectly. There is now a single parameter `-Range`, with an alias of "Address". If the worksheet parameter is present, the function accepts a string specifying cells ("A1:Z10") or a the name of range. Withouth the worksheet it accepts an object representing a named range or a Table; or a tables's address, or part of the worksheet.cells collection. +- `Add-ConditionalFormatting`: Used "address" correctly, and it will accept ranges in the address parameter (range is now an alias for address). It now wraps conditional value strings in quotes when needed (for = <= >= operations string needs to be in double quotes see issue #424). Parameter intellisense has been improved. There are new parameters: `-StopIfTrue` and `-Priority` and support for using the `-Reverse` parameter with Color-scale rules (issue #430). Booleans in the sheet are now supported as the value for a condition. Also brought the two different kinds of condition together inside Export-Excel, and fixed a bug where named-ranges didn't work in some places. In `New-ConditionalText`, more types of conditional format are supported, and the argument completer for -ConditionalTextColor was missing and has been added. +- Improved handling of hyperlinks in `Export-Excel` (see issue #426)s - `Export-Excel` has better checking of Table and PivotTable names (for uniqueness) and a new test in quick charts that there is suitable data for charting. It also accepts hash tables for chart, pivot table and conditional formatting parameters which are splatted into the functions which add these. -- Moved logic for adding a named range out of Export-Excel and into a new function named `Add-ExcelName`, and logic for adding a table into a function named `Add-ExcelTable`; this is to make it easier to do these things independently of Export-Excel, but minimize duplication. The Add-ExcelTable command has extra parameters to toggle the options from table tools toolbar (show totals etc) and set options in the totals row. +- Moved logic for adding a named-range out of Export-Excel and into a new function named `Add-ExcelName`, and logic for adding a table into a function named `Add-ExcelTable`; this is to make it easier to do these things independently of Export-Excel, but minimize duplication. The Add-ExcelTable command has extra parameters to toggle the options from table tools toolbar (show totals etc) and set options in the totals row. - Moved PivotTable Functions out of Export-Excel.PS1 into their own file and moved Add-ExcelChart out of Export-Excel.ps1 into New-ExcelChart.ps1 +- Fixed bug in Merge-MultipleSheets where background pattern was set to None, making background color invisible. - Fixed issues where formatting could be reset when using Export-Excel to manipulate an existing sheet without appending data; this applied to number-formats and tables. -- `Add-PivotTable` has some new parameters -PassThru returns the pivot table (e.g. to allow names /sort orders of data series to be tweaked ) -Address parameter allows Pivot to be placed on an existing sheet; -PivotTableStyle allows a change from "Medium6", -PivotNumberFormat formats data cells. It is more flexible about how the source data is specified. Chart creation has been moved out to Add-ExcelChart, and -PivotChartDefinition allows a defintion created with New-ExcelChartDefinition to be used with a PivotTable. This opens up all the things that Add-ExcelChart can do without duplicating the parameters on Add-Pivot table and Export-Excel. Definition, TableStyle, Numberformat and ChartDefiniton can be used in `New-PivotTableDefinition` . +- `Add-PivotTable` has some new parameters `-PassThru` returns the pivot table (e.g. to allow names /sort orders of data series to be tweaked ) `-Address` allows Pivot to be placed on an existing sheet; `-PivotTableStyle` allows a change from "Medium6", `-PivotNumberFormat` formats data cells. It is more flexible about how the source data is specified - copying the range options in Set-ExcelRange. `Add-ExcelChart` is now used for creating PivotCharts, and `-PivotChartDefinition` allows a defintion created with `New-ExcelChartDefinition` to be used when setting up a PivotTable. This opens up all the things that Add-ExcelChart can do without duplicating the parameters on Add-Pivot table and Export-Excel. Definition, TableStyle, Numberformat and ChartDefiniton can be used in `New-PivotTableDefinition` . - `Add-ExcelChart` now supports -PassThru to return the chart for tweaking after creation; there is now a -PivotTable parameter to allow Add-PivotTable to call the code in Add-ExcelChart. And in `New-ExcelChartDefinition` Legend parameters (for size, bold & position ) are now supported -- ChartDefinition and conditional formatting parameters can now be hashtables - if it would will splat into Add-ExcelChart or Add-ConditionalFormatting, it should be acceptable as a definition. +- ChartDefinition and conditional formatting parameters can now be hashtables - antything that splats Add-ExcelChart or Add-ConditionalFormatting, it should be acceptable as a definition. # What's new in Release 5.2 diff --git a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 index f7cf51f..80f1f0d 100644 --- a/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 +++ b/__tests__/Set-Row_Set-Column-SetFormat.tests.ps1 @@ -304,16 +304,6 @@ ID,Product,Quantity,Price,Total Describe "Table Formatting" { BeforeAll { - Remove-Item $path - $excel = $data2 | Export-excel -path $path -WorksheetName Hardware -AutoNameRange -AutoSize -BoldTopRow -FreezeTopRow -PassThru - $ws = $excel.Workbook.Worksheets[1] - Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName HardwareTable -TotalSettings @{"Total"="Sum"} -ShowFirstColumn -ShowFilter:$false - - Set-ExcelColumn -Worksheet $ws -Column 4 -NumberFormat 'Currency' - Set-ExcelColumn -Worksheet $ws -Column 5 -NumberFormat 'Currency' - - $PtDef =New-PivotTableDefinition -PivotTableName Totals -PivotRows Product -PivotData @{"Total"="Sum"} -PivotNumberFormat Currency -PivotTotals None -PivotTableSyle Dark2 - Export-excel -ExcelPackage $excel -WorksheetName Hardware -PivotTableDefinition $PtDef Remove-Item $path $excel = $data2 | Export-excel -path $path -WorksheetName Hardware -AutoNameRange -AutoSize -BoldTopRow -FreezeTopRow -PassThru $ws = $excel.Workbook.Worksheets[1]