excel sheet的着色细胞

时间:2011-05-02 16:44:36

标签: c# excel colors cells

我想在c#中为excel表格的某些特定单元格着色。但我没有得到它.. 我使用的代码为:

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

但这并非如此...... 如何做到这一点.. 请做点什么.. 它给出了一个错误“无法解决符号'内部'”

1 个答案:

答案 0 :(得分:2)

尝试Range.Interior属性:

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

其中work_sheet是要更改单元格的Excel.Worksheet。 rowcolumn或要更改的单元格的索引。

您的示例可能正在返回列索引器的对象。试试这个:

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