1
1
try {Import-Module $PSScriptRoot \..\..\ImportExcel.psd1} catch {throw ; return }
2
2
3
3
# Get rid of pre-exisiting sheet
4
- $path = " $Env: TEMP \test.xlsx"
5
- remove-item - Path $path - ErrorAction SilentlyContinue
4
+ $xlSourcefile = " $env: TEMP \ImportExcelExample.xlsx"
5
+ Write-Verbose - Verbose - Message " Save location: $xlSourcefile "
6
+ Remove-Item $xlSourcefile - ErrorAction Ignore
6
7
7
8
# Create simple pages for 3 stores with product ID, Product Name, quanity price and total
8
9
@@ -13,7 +14,7 @@ ID,Product,Quantity,Price,Total
13
14
12003,Saw,12,15.37,184.44
14
15
12010,Drill,20,8,160
15
16
12011,Crowbar,7,23.48,164.36
16
- "@ | ConvertFrom-Csv | Export-Excel - Path $path - WorkSheetname Oxford
17
+ "@ | ConvertFrom-Csv | Export-Excel - Path $xlSourcefile - WorkSheetname Oxford
17
18
18
19
@"
19
20
ID,Product,Quantity,Price,Total
@@ -22,7 +23,7 @@ ID,Product,Quantity,Price,Total
22
23
12003,Saw,10,15.37,153.70
23
24
12010,Drill,10,8,80
24
25
12012,Pliers,2,14.99,29.98
25
- "@ | ConvertFrom-Csv | Export-Excel - Path $path - WorkSheetname Abingdon
26
+ "@ | ConvertFrom-Csv | Export-Excel - Path $xlSourcefile - WorkSheetname Abingdon
26
27
27
28
28
29
@"
@@ -31,7 +32,7 @@ ID,Product,Quantity,Price,Total
31
32
12002,Hammer,2,12.10,24.20
32
33
12010,Drill,11,8,88
33
34
12012,Pliers,3,14.99,44.97
34
- "@ | ConvertFrom-Csv | Export-Excel - Path $path - WorkSheetname Banbury
35
+ "@ | ConvertFrom-Csv | Export-Excel - Path $xlSourcefile - WorkSheetname Banbury
35
36
36
37
# define a pivot table with a chart to show a sales by store, broken down by product
37
38
$ptdef = New-PivotTableDefinition - PivotTableName " Summary" - PivotRows " Store" - PivotColumns " Product" - PivotData @ {" Total" = " SUM" } - IncludePivotChart - ChartTitle " Sales Breakdown" - ChartType ColumnStacked - ChartColumn 10
@@ -42,4 +43,4 @@ $ptdef = New-PivotTableDefinition -PivotTableName "Summary" -PivotRows "Store" -
42
43
# Put in a title and freeze to top of the sheet including title and colmun headings
43
44
# Add the Pivot table.
44
45
# Show the result
45
- Join-Worksheet - Path $path - WorkSheetName " Total" - Clearsheet - FromLabel " Store" - TableName " Combined" - TableStyle Light1 - AutoSize - BoldTopRow - FreezePane 2 , 1 - Title " Store Sales Summary" - TitleBold - TitleSize 14 - PivotTableDefinition $ptdef - show
46
+ Join-Worksheet - Path $xlSourcefile - WorkSheetName " Total" - Clearsheet - FromLabel " Store" - TableName " Combined" - TableStyle Light1 - AutoSize - BoldTopRow - FreezePane 2 , 1 - Title " Store Sales Summary" - TitleBold - TitleSize 14 - PivotTableDefinition $ptdef - show
0 commit comments