Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created September 20, 2024 13:43
Show Gist options
  • Save dfinke/f084beadbe2a6f119385359b2bc351d0 to your computer and use it in GitHub Desktop.
Save dfinke/f084beadbe2a6f119385359b2bc351d0 to your computer and use it in GitHub Desktop.
Create Excel bar chart using PowerShell by repeating symbols based on values with custom styling
$data = ConvertFrom-Csv @"
Name,UnitsSold
John,100
Jane,200
Tom,120
Jane,300
Jim,150
Mary,250
"@
$xlFile = "$PSScriptRoot\spike.xlsx"
Remove-Item $xlFile -ErrorAction SilentlyContinue
$xlPkg = $data | Export-Excel -Path $xlFile -AutoSize -PassThru
Set-ExcelRange -Worksheet $xlPkg.Sheet1 -Range 'C1:C1' -Value 'Plot'
Set-ExcelRange -Worksheet $xlPkg.Sheet1 -Width 35 `
-Range 'C2:C7' -Formula '=REPT("|",B2)' `
-FontName 'Playbill' -FontColor "Green"
Close-ExcelPackage $xlPkg -Show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment