PowerShell EPPlus unable to change Backgroundcolor of Cells
Clash Royale CLAN TAG#URR8PPP
PowerShell EPPlus unable to change Backgroundcolor of Cells
I am creating an Excel Document using EPPlus. It is working, but I am not able to change the Background Color of Cells.
I use the following code for it:
Worksheet.Cells[row,column].Style.Fill.BackgroundColor.rgb = (255,0,0)
Everytime I execute the script it says:
"rgb" is a read-only property
When I try to set the
Worksheet.Cells.Style.Fill.BackgroundColor = xxx
I get the same error:
"BackgroundColor" is a read-only property
I did not find more options, where you might change the Color or change the property to writeable...
Does anyone have an idea?
2 Answers
2
Try my PowerShell Excel module that wraps EPPlus and makes interaction really easy.
https://www.powershellgallery.com/packages/ImportExcel/
$xlfile = "$env:TEMPtest.xlsx"
rm $xlfile -ErrorAction Ignore
$pkg = ps | select company, Handles| Export-Excel $xlfile -PassThru
$ws = $pkg.Workbook.Worksheets["Sheet1"]
Set-Format -WorkSheet $ws -Range "B2:B2" -BackgroundColor Red
Set-Format -WorkSheet $ws -Range "B5:B5" -BackgroundColor Green
Close-ExcelPackage $pkg -Show
You set the color like this.
Worksheet.Cells[row,column].Style.Fill.PatternType = ExcelFillStyle.Solid;
Worksheet.Cells[row,column].Style.Fill.BackgroundColor.SetColor(Color.Red);
Yes this is C#.
– VDWWD
Aug 3 at 18:46
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks, but unfortunately this is not working for me. It says ")" is missing.. Your code is in c# right? I want to use the same in PowerShell..
– grisch111
Aug 3 at 13:43