PowerShell EPPlus unable to change Backgroundcolor of Cells

The name of the pictureThe name of the pictureThe name of the pictureClash 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/



enter image description here


$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);





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






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.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS