How do you set the font color in an EXCEL cell?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range


xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set of
enumerations of colors that will work here?
 
Darrell,

I am in doubt if it is the same colourcode as the Interop wants, however a
colour in VBNet is just easy to get with Color.Red (it is a enum so a bunch
of colours is showed)

I hope this helps?

Cor
 
Hi
xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

Excel-Workbook:
xlWB.Colors(1) = RGB(255,255,255)
xlWB.Colors(2) = RGB(225,225,225)
xlWB.Colors(3) = RGB(200,200,200)

Excel-Worksheet
xlWS.Range("A1:A30").Interior.ColorIndex = 1
xlWS.Range("B1:B30").Interior.ColorIndex = 2
xlWS.Range("C1:C30").Interior.ColorIndex = 3

This works fine for me

Frank
 
Darrell Wesley said:
Where xlWs is an Excel.Worksheet and xlRG is an Excel.Range


xlRG = xlWS.Cells(row, 7)
xlRG.Font.Bold = True
xlRG.Font.Color = 255

In VB6 you could just simply say xlRG.Font.Color = vbRed but in .net there
is no constant vbRed and Color.Red gives an invalid format. Is there a set of
enumerations of colors that will work here?



Hi Darrell,

What was the exact message? May it is a casting problem.


TTH,
Adel A. Al-saleh
 
Finally found out how to do this:

xlRG.Font.Color = System.Drawing.Color.ColorTranslator.ToOle(Color.Red)

and to set the cell background color

xlRG.Interior.Color =
System.Drawing.Color.ColorTranslator.ToOle(Color.LightBlue)
xlRG.Interior.Pattern = Excel.XlPattern.xlPatternSolid
 
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor
 
You are so right. Thanks.

Cor Ligthert said:
Darell,

Thanks for the page, however there it is not described as you did it.

Colorconverter is a method from system.drawing not from
system.drawing.color.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top