coloring cells of excel sheet

有些话、适合烂在心里 提交于 2019-12-11 23:42: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:


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);


来源:https://stackoverflow.com/questions/5859857/coloring-cells-of-excel-sheet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!