为 excel 中的单元格组设置颜色

Set color to group of cells in excel

目前我们正在使用以下代码设置单元格中的颜色,

worksheet.Cells[18, 1].Style.Fill.BackgroundColor.SetColor(Constants.highlightingColor);

有什么方法可以为一组单元格设置颜色吗?就像我们使用 class 名称在 css 中的元素组中设置颜色。

如果您希望一次设置一系列单元格,您可以简单地使用 Cells 对象索引器重载。像这样:

worksheet.Cells[18,1,28,11].Style.Fill.BackgroundColor.SetColor(Constants.highlightingColor);

将从第 18 行第 1 列的单元格开始,转到第 28 行第 11 列的单元格并设置所有背景颜色。