Andrei Andre
Andrei Andre

Reputation: 177

Why can't change the fill color of a cell using C#?

Based on :

coloring cells of excel sheet

I put this line of code

Range data_cell = work_sheet.Cells[row, column];
data_cell.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DeepPink);

I added the System.Drawing dll file + added the import line in my file

using System.Drawing;

but I still receive this message:

cannot resolve symbol "ColorTranslator"

Any suggestions to resolve this situation?

Upvotes: 0

Views: 1162

Answers (1)

Shai
Shai

Reputation: 25619

If you want to change the background color of a cell,

                Range myRange = work_sheet.get_Range("A1", "A1");
                myRange.Interior.ColorIndex = 6;

This will paint the A1 cell

EDIT: Couldn't find a good reference for ColorIndex, but here's an image of all of the colors 6, in our example, is Yellow.

Upvotes: 1

Related Questions