mucchar
mucchar

Reputation: 3

coloring cells of excel sheet

I want to color some particular cells of excel sheet in c#. but I am not getting it.. I am using the code as:

  dsNew.Tables[0].Columns[j].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DeepPink);

but this is not wrking.. how this can be done.. please do something.. it is giving an error "cannot resolve symbol'interior'"

Upvotes: 0

Views: 2867

Answers (1)

SwDevMan81
SwDevMan81

Reputation: 49978

Try the Range.Interior property:

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

where work_sheet is the Excel.Worksheet you wish to change the cells of. row and column or the indices of the cells to change.

Your example may be returning an object for the column indexer. Try this:

((Range)dsNew.Tables[0].Columns[j]).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DeepPink);

Upvotes: 2

Related Questions