Updates to examples . Minor bug fix to format in Merge-Multiple

This commit is contained in:
jhoneill
2018-09-10 14:26:29 +01:00
parent 65b1f79d53
commit ef4ac9777b
25 changed files with 326 additions and 72 deletions

View File

@@ -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

View File

@@ -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
)

View File

@@ -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

View File

@@ -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

View File

@@ -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 <parameters> .... ; Export-excel -conditionalText $variable <other parameters>
# the syntax is used is Export-excel -conditionalText (New-Conditional text <parameters>) <other parameters>
#$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage)

View File

@@ -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

View File

@@ -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
1 Race Date FinishPosition Driver GridPosition Team Points
2 Australian 25/03/2018 1 Sebastian Vettel 3 Ferrari 25
3 Australian 25/03/2018 2 Lewis Hamilton 1 Mercedes 18
4 Australian 25/03/2018 3 Kimi Räikkönen 2 Ferrari 15
5 Australian 25/03/2018 4 Daniel Ricciardo 8 Red Bull Racing-TAG Heuer 12
6 Australian 25/03/2018 5 Fernando Alonso 10 McLaren-Renault 10
7 Australian 25/03/2018 6 Max Verstappen 4 Red Bull Racing-TAG Heuer 8
8 Australian 25/03/2018 7 Nico Hülkenberg 7 Renault 6
9 Australian 25/03/2018 8 Valtteri Bottas 15 Mercedes 4
10 Australian 25/03/2018 9 Stoffel Vandoorne 11 McLaren-Renault 2
11 Australian 25/03/2018 10 Carlos Sainz 9 Renault 1
12 Bahrain 08/04/2018 1 Sebastian Vettel 1 Ferrari 25
13 Bahrain 08/04/2018 2 Valtteri Bottas 3 Mercedes 18
14 Bahrain 08/04/2018 3 Lewis Hamilton 9 Mercedes 15
15 Bahrain 08/04/2018 4 Pierre Gasly 5 STR-Honda 12
16 Bahrain 08/04/2018 5 Kevin Magnussen 6 Haas-Ferrari 10
17 Bahrain 08/04/2018 6 Nico Hülkenberg 7 Renault 8
18 Bahrain 08/04/2018 7 Fernando Alonso 13 McLaren-Renault 6
19 Bahrain 08/04/2018 8 Stoffel Vandoorne 14 McLaren-Renault 4
20 Bahrain 08/04/2018 9 Marcus Ericsson 17 Sauber-Ferrari 2
21 Bahrain 08/04/2018 10 Esteban Ocon 8 Force India-Mercedes 1
22 Chinese 15/04/2018 1 Daniel Ricciardo 6 Red Bull Racing-TAG Heuer 25
23 Chinese 15/04/2018 2 Valtteri Bottas 3 Mercedes 18
24 Chinese 15/04/2018 3 Kimi Räikkönen 2 Ferrari 15
25 Chinese 15/04/2018 4 Lewis Hamilton 4 Mercedes 12
26 Chinese 15/04/2018 5 Max Verstappen 5 Red Bull Racing-TAG Heuer 10
27 Chinese 15/04/2018 6 Nico Hülkenberg 7 Renault 8
28 Chinese 15/04/2018 7 Fernando Alonso 13 McLaren-Renault 6
29 Chinese 15/04/2018 8 Sebastian Vettel 1 Ferrari 4
30 Chinese 15/04/2018 9 Carlos Sainz 9 Renault 2
31 Chinese 15/04/2018 10 Kevin Magnussen 11 Haas-Ferrari 1
32 Azerbaijan 29/04/2018 1 Lewis Hamilton 2 Mercedes 25
33 Azerbaijan 29/04/2018 2 Kimi Räikkönen 6 Ferrari 18
34 Azerbaijan 29/04/2018 3 Sergio Pérez 8 Force India-Mercedes 15
35 Azerbaijan 29/04/2018 4 Sebastian Vettel 1 Ferrari 12
36 Azerbaijan 29/04/2018 5 Carlos Sainz 9 Renault 10
37 Azerbaijan 29/04/2018 6 Charles Leclerc 13 Sauber-Ferrari 8
38 Azerbaijan 29/04/2018 7 Fernando Alonso 12 McLaren-Renault 6
39 Azerbaijan 29/04/2018 8 Lance Stroll 10 Williams-Mercedes 4
40 Azerbaijan 29/04/2018 9 Stoffel Vandoorne 16 McLaren-Renault 2
41 Azerbaijan 29/04/2018 10 Brendon Hartley 19 STR-Honda 1
42 Spanish 13/05/2018 1 Lewis Hamilton 1 Mercedes 25
43 Spanish 13/05/2018 2 Valtteri Bottas 2 Mercedes 18
44 Spanish 13/05/2018 3 Max Verstappen 5 Red Bull Racing-TAG Heuer 15
45 Spanish 13/05/2018 4 Sebastian Vettel 3 Ferrari 12
46 Spanish 13/05/2018 5 Daniel Ricciardo 6 Red Bull Racing-TAG Heuer 10
47 Spanish 13/05/2018 6 Kevin Magnussen 7 Haas-Ferrari 8
48 Spanish 13/05/2018 7 Carlos Sainz 9 Renault 6
49 Spanish 13/05/2018 8 Fernando Alonso 8 McLaren-Renault 4
50 Spanish 13/05/2018 9 Sergio Pérez 15 Force India-Mercedes 2
51 Spanish 13/05/2018 10 Charles Leclerc 14 Sauber-Ferrari 1
52 Monaco 27/05/2018 1 Daniel Ricciardo 1 Red Bull Racing-TAG Heuer 25
53 Monaco 27/05/2018 2 Sebastian Vettel 2 Ferrari 18
54 Monaco 27/05/2018 3 Lewis Hamilton 3 Mercedes 15
55 Monaco 27/05/2018 4 Kimi Räikkönen 4 Ferrari 12
56 Monaco 27/05/2018 5 Valtteri Bottas 5 Mercedes 10
57 Monaco 27/05/2018 6 Esteban Ocon 6 Force India-Mercedes 8
58 Monaco 27/05/2018 7 Pierre Gasly 10 STR-Honda 6
59 Monaco 27/05/2018 8 Nico Hülkenberg 11 Renault 4
60 Monaco 27/05/2018 9 Max Verstappen 20 Red Bull Racing-TAG Heuer 2
61 Monaco 27/05/2018 10 Carlos Sainz 8 Renault 1
62 Canadian 10/06/2018 1 Sebastian Vettel 1 Ferrari 25
63 Canadian 10/06/2018 2 Valtteri Bottas 2 Mercedes 18
64 Canadian 10/06/2018 3 Max Verstappen 3 Red Bull Racing-TAG Heuer 15
65 Canadian 10/06/2018 4 Daniel Ricciardo 6 Red Bull Racing-TAG Heuer 12
66 Canadian 10/06/2018 5 Lewis Hamilton 4 Mercedes 10
67 Canadian 10/06/2018 6 Kimi Räikkönen 5 Ferrari 8
68 Canadian 10/06/2018 7 Nico Hülkenberg 7 Renault 6
69 Canadian 10/06/2018 8 Carlos Sainz 9 Renault 4
70 Canadian 10/06/2018 9 Esteban Ocon 8 Force India-Mercedes 2
71 Canadian 10/06/2018 10 Charles Leclerc 13 Sauber-Ferrari 1
72 French 24/06/2018 1 Lewis Hamilton 1 Mercedes 25
73 French 24/06/2018 2 Max Verstappen 4 Red Bull Racing-TAG Heuer 18
74 French 24/06/2018 3 Kimi Räikkönen 6 Ferrari 15
75 French 24/06/2018 4 Daniel Ricciardo 5 Red Bull Racing-TAG Heuer 12
76 French 24/06/2018 5 Sebastian Vettel 3 Ferrari 10
77 French 24/06/2018 6 Kevin Magnussen 9 Haas-Ferrari 8
78 French 24/06/2018 7 Valtteri Bottas 2 Mercedes 6
79 French 24/06/2018 8 Carlos Sainz 7 Renault 4
80 French 24/06/2018 9 Nico Hülkenberg 12 Renault 2
81 French 24/06/2018 10 Charles Leclerc 8 Sauber-Ferrari 1
82 Austrian 01/07/2018 1 Max Verstappen 4 Red Bull Racing-TAG Heuer 25
83 Austrian 01/07/2018 2 Kimi Räikkönen 3 Ferrari 18
84 Austrian 01/07/2018 3 Sebastian Vettel 6 Ferrari 15
85 Austrian 01/07/2018 4 Romain Grosjean 5 Haas-Ferrari 12
86 Austrian 01/07/2018 5 Kevin Magnussen 8 Haas-Ferrari 10
87 Austrian 01/07/2018 6 Esteban Ocon 11 Force India-Mercedes 8
88 Austrian 01/07/2018 7 Sergio Pérez 15 Force India-Mercedes 6
89 Austrian 01/07/2018 8 Fernando Alonso 20 McLaren-Renault 4
90 Austrian 01/07/2018 9 Charles Leclerc 17 Sauber-Ferrari 2
91 Austrian 01/07/2018 10 Marcus Ericsson 18 Sauber-Ferrari 1
92 British 08/07/2018 1 Sebastian Vettel 2 Ferrari 25
93 British 08/07/2018 2 Lewis Hamilton 1 Mercedes 18
94 British 08/07/2018 3 Kimi Räikkönen 3 Ferrari 15
95 British 08/07/2018 4 Valtteri Bottas 4 Mercedes 12
96 British 08/07/2018 5 Daniel Ricciardo 6 Red Bull Racing-TAG Heuer 10
97 British 08/07/2018 6 Nico Hülkenberg 11 Renault 8
98 British 08/07/2018 7 Esteban Ocon 10 Force India-Mercedes 6
99 British 08/07/2018 8 Fernando Alonso 13 McLaren-Renault 4
100 British 08/07/2018 9 Kevin Magnussen 7 Haas-Ferrari 2
101 British 08/07/2018 10 Sergio Pérez 12 Force India-Mercedes 1

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
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'

View File

@@ -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"

View File

@@ -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'

View File

@@ -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

View File

@@ -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
<# 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
#>

View File

@@ -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

View File

@@ -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
#>

View File

@@ -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

View File

@@ -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 |

View File

@@ -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()]

View File

@@ -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

View File

@@ -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

View File

@@ -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]