coloring cells of excel sheet

2019-09-05 23:03发布

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'"

1条回答
来,给爷笑一个
2楼-- · 2019-09-05 23:24

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);
查看更多
登录 后发表回答