Hi,
I would like to set the cell background color (and font color later) for a
range of cells in excel using a c# application.
First I set the BackColor of a textbox on a windows form to the color I
would like to apply to the Excel cell/range. the color in this case is
RGB(255,128,128) or {RGB=0xffff8080} from the colorDialog.
The following works fine but I need to replace the "255" with the Backcolor
of the textbox.
rng = (Excel.Range)ws.Cells[2,2];
ws.get_Range(rng,rng).Interior.Color = 255; Red
or
ws.get_Range(rng,rng).Interior.Color = 65535; Yellow
In vba I can use :
Cells(1, 1).Interior.Color = RGB(255, 128, 128)
But I haven't managed to get the automation from c# to work.
Any assistance welcome :-)
Cheers
Olan
Dirk Behnke - 26 Aug 2005 19:16 GMT
> Hi,
>
[quoted text clipped - 23 lines]
> Cheers
> Olan
Hi,
use
Cells(1.1).Interior.Color=System.Drawing.Color.FromArgb(yourTextBox.BackColor.R,yourTextBox..BackColor.G,yourTextBox..BackColor.B);
Regards,
Dirk
sprasad - 14 Nov 2005 07:49 GMT
Hi,
I have tried setting the color using System.Drawing.Color.FromArgb,but it
gives type mismatch..
Regards,
Prasad
> > Hi,
> >
[quoted text clipped - 30 lines]
> Regards,
> Dirk
Dirk Behnke - 18 Nov 2005 13:22 GMT
> Hi,
> I have tried setting the color using System.Drawing.Color.FromArgb,but it
[quoted text clipped - 37 lines]
>>Regards,
>>Dirk
Just
Cells(1.1).Interior.Color=System.Drawing.Color.FromArgb(yourTextBox.BackColor.R,yourTextBox.BackColor.G,yourTextBox..BackColor.B).ToArgb;
I'm now just wondering if there is an easier way to achieve that. Seems
to be some duplication