From f2b47373e18951af308b223c856710d332b8f151 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 21 Feb 2016 17:25:29 -0500 Subject: [PATCH] PassThru example --- Examples/PassThru/TryPassThru.ps1 | 23 +++++++++++++++++++++++ Examples/PassThru/sales.csv | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Examples/PassThru/TryPassThru.ps1 create mode 100644 Examples/PassThru/sales.csv diff --git a/Examples/PassThru/TryPassThru.ps1 b/Examples/PassThru/TryPassThru.ps1 new file mode 100644 index 0000000..0a7591a --- /dev/null +++ b/Examples/PassThru/TryPassThru.ps1 @@ -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 \ No newline at end of file diff --git a/Examples/PassThru/sales.csv b/Examples/PassThru/sales.csv new file mode 100644 index 0000000..3af4e35 --- /dev/null +++ b/Examples/PassThru/sales.csv @@ -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" \ No newline at end of file