使用Epplus如何将整行背景色设置为红色?我有这个
int rowNumber = ws.Cells[rowIndex].Value;
ws.Cells[rowIndex].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;但我的错误是
Can not convert from int to string on [rowIndex]使用C#和epplus设置行颜色的正确方法是什么?
发布于 2022-05-06 12:59:25
因为ExcelRange类是ws.Cells,所以当您使用带有一个参数的[ ]时,您应该得到一个Address字符串。
ws.Cells[string Address]您可以将它与rowIndex和col结合使用,以到达一个单元格,然后添加颜色:
int col = 1;
int rowIndex = 1;
//in SetColor Method use ColorRgb
ws.Cells[rowIndex, col].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(255, 0, 0));
ws.Cells[rowIndex, col].Style.Font.Bold = true;如果要将颜色修改为多行而不是单元格,请使用以下命令:
ws.Cells[int FromRow, int FromCol, int ToRow, int ToCol]这样,您就可以到达所有的前二十列,并为它们设置颜色。
https://stackoverflow.com/questions/72141723
复制相似问题