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

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