PassThru example

This commit is contained in:
dfinke
2016-02-21 17:25:29 -05:00
parent 79d89b3bc5
commit f2b47373e1
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
$file = "sales.xlsx"
rm $file -ErrorAction Ignore
$xlPkg = Import-Csv .\sales.csv | Export-Excel $file -PassThru
$ws = $xlPkg.Workbook.WorkSheets[1]
$ws.Cells["E1"].Value = "TotalSold"
$ws.Cells["F1"].Value = "Add 10%"
2..($ws.Dimension.Rows) |
ForEach {
$ws.Cells["E$_"].Formula = "=C$_+D$_"
$ws.Cells["F$_"].Formula = "=E$_+(10%*(C$_+D$_))"
}
$ws.Cells.AutoFitColumns()
$xlPkg.Save()
$xlPkg.Dispose()
Invoke-Item $file

View File

@@ -0,0 +1,26 @@
"Region","Item","UnitSold","UnitCost"
"South","Banana","54","0.46"
"West","Banana","74","0.56"
"West","Apple","26","0.7"
"East","Banana","38","0.26"
"East","Kale","71","0.69"
"East","Apple","35","0.55"
"East","Potato","48","0.48"
"West","Banana","59","0.49"
"West","Potato","56","0.62"
"North","Apple","40","0.68"
"South","Pear","39","0.44"
"West","Banana","60","0.64"
"West","Pear","32","0.29"
"North","Kale","55","0.35"
"West","Apple","73","0.26"
"South","Potato","33","0.46"
"West","Banana","49","0.59"
"West","Pear","65","0.35"
"North","Banana","33","0.31"
"East","Kale","41","0.74"
"South","Banana","49","0.31"
"West","Apple","60","0.34"
"South","Apple","38","0.59"
"North","Pear","29","0.74"
"West","Kale","67","0.38"
1 Region Item UnitSold UnitCost
2 South Banana 54 0.46
3 West Banana 74 0.56
4 West Apple 26 0.7
5 East Banana 38 0.26
6 East Kale 71 0.69
7 East Apple 35 0.55
8 East Potato 48 0.48
9 West Banana 59 0.49
10 West Potato 56 0.62
11 North Apple 40 0.68
12 South Pear 39 0.44
13 West Banana 60 0.64
14 West Pear 32 0.29
15 North Kale 55 0.35
16 West Apple 73 0.26
17 South Potato 33 0.46
18 West Banana 49 0.59
19 West Pear 65 0.35
20 North Banana 33 0.31
21 East Kale 41 0.74
22 South Banana 49 0.31
23 West Apple 60 0.34
24 South Apple 38 0.59
25 North Pear 29 0.74
26 West Kale 67 0.38