I'm developing an program using C# to manipulate an Excel document, and I'm using
Microsoft.Office.Interop.Excel._Worksheet worksheet;
When I insert something to a x,y cell I use :
worksheet.Cells[x, y] = "something";
Now I want to know if it's possible to change the backColor
of the Cells[x,y] from C#.
Thank you.
Select the cell or range of cells you want to format. Click Home > Format Cells dialog launcher, or press Ctrl+Shift+F. On the Fill tab, under Background Color, pick the color you want.
Apply an If-Then rule to all cells by pressing “Ctrl-A” before assigning your rule. If you copy values from colored cells and paste them into new it new cells, the new cells acquire the color of the copied cell.
Try
worksheet.Cells[x, y].Interior.Color
You won't be able to use the Colors in .Net directly, they will require a translation.
It is recommended to use the following (obviously change from silver) :
worksheet.Cells[x, y].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Silver);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With