Set Backcolor of a Excel cell

  • Thread starter Thread starter Barry
  • Start date Start date
B

Barry

Hi

In C# i can set the backcolor of a cell like this

worksheet.get_Range("B1:B1", Type.Missing).Interior.ColorIndex = 1;

I need to set the color without using ColorIndex, ie any color using
Color.FromARGB(205, 255, 255)

I tried the following
worksheet.get_Range("B1:B1", Type.Missing).Interior.Color =
Color.FromARGB(205,255,255);

But it show an error.

Does someone know how to acheve this.


TIA
Barry
 
Barry,

It looks like your're assigning a Color to the cell, since Color.FromARGB
returns a Color structure. The Interior.Color property is a 32-bit number.
Have you tried using ToArgb, as in:

Cell.Interior.Color = Drawing.Color.FromArgb(205, 255, 255).ToArgb.

James
 
This could have solved the problem, but
Color.FromArgb(205, 255, 255).ToArgb(); returns -3276801
any idea what could be the problem
 
The color that the Excel interop is expecting is a 16-bit unsigned integer.
However, VB treats the ToArgb return value as a signed integer. Because the
bytes are passed as an Object, Excel has no trouble interpreting the value
correctly. Unfortunately, I don't know of any way in VB to show the actual
unsigned value, but a search of MSDN might find an easy solution.
 
Hi James

Thanks for your reponse.

Happened to see your reply today.

I was using C# not VB, since i wanted an answer quickly, i added a reference
to VisualBasic and used the following

Microsoft.VisualBasic.Information.RGB(205, 255,255)

Barry
 
Back
Top