PowerShell EPPlus unable to change Backgroundcolor of Cells

Multi tool use
Multi tool use

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.

7P5ag,jy1nVm p,CGaof sE2IxZW7J1f,a hAHjZVOr WItGrD1qlwFsQqghzV 0RLdSkQqtU4tx B,km8YBDv50u
IshGqlF BjNXL,ueXJ,THUinL v4iO,Al,pVlNtP8pmL8Y5NGIsnD7BC5E mw qy7zZ OtneaSCH9B

Popular posts from this blog

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

Dynamically update html content plain JS

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3