This commit is contained in:
dfinke
2018-07-04 19:51:35 -04:00
parent 6c449bd9ce
commit b641ce915f

View File

@@ -2,22 +2,21 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
$excel = $(
New-PSItem Jan 1277 (echo Month Sales)
New-PSItem Feb 1003
New-PSItem Mar 1105
New-PSItem Apr 952
New-PSItem May 770
New-PSItem Jun 621
) | Export-Excel .\test.xlsx -PassThru -AutoNameRange
$excel = @"
Month,Sales
Jan,1277
Feb,1003
Mar,1105
Apr,952
May,770
Jun,621
"@ | ConvertFrom-csv |
Export-Excel -Path .\test.xlsx -WorkSheetname Sheet1 -AutoNameRange -PassThru
$sheet = $excel.Workbook.Worksheets["Sheet1"]
Add-ConditionalFormatting -WorkSheet $sheet -Range "B1:B7" -DataBarColor LawnGreen
$targetRow = $sheet.dimension.Rows + 1
Set-Format -Address $sheet.Cells["A$($targetRow)"] -Value "Total"
Set-Format -Address $sheet.Cells["B$($targetRow)"] -Formula "=Sum(Sales)"
Set-Format -Address $sheet.Cells["A8"] -Value "Total"
Set-Format -Address $sheet.Cells["B8"] -Formula "=Sum(Sales)"
Close-ExcelPackage $excel -Show