Files
ImportExcel/Examples/PassThru/TryPassThru.ps1
2018-07-05 16:14:56 -04:00

25 lines
519 B
PowerShell

try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
$file = "sales.xlsx"
Remove-Item $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-Object {
$ws.Cells["E$_"].Formula = "=C$_+D$_"
$ws.Cells["F$_"].Formula = "=E$_+(10%*(C$_+D$_))"
}
$ws.Cells.AutoFitColumns()
$xlPkg.Save()
$xlPkg.Dispose()
Invoke-Item $file