根据列值使用 closedXML 设置行颜色

Set row color with closedXML based on column value

我正在尝试使用 VB.NET 从数据表写入 Excel 文件。我也能够实现很少的 excel 操作。现在我想根据特定列的单元格值(例如 Col-4)为一行着色。这是我的 Excel 文件 -

Here is my Excel file

I want to achieve like this -

寻找一些指导来实现这一点。

我建议您添加条件格式。例如:

var workbook = new XLWorkbook();
var ws = workbook.AddWorksheet("Sheet1");

ws.FirstCell().SetValue(1)
  .CellBelow().SetValue(1)
  .CellBelow().SetValue(2)
  .CellBelow().SetValue(3)
  .CellBelow().SetValue(4);

ws.RangeUsed().AddConditionalFormat().WhenBetween(2, 3)
  .Fill.SetBackgroundColor(XLColor.Red);

参考:https://github.com/ClosedXML/ClosedXML/wiki/Conditional-Formatting