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

问题描述 投票:0回答:1

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

Here is my Excel file

I want to achieve like this -

寻求一些指导来实现这一目标。

closedxml
1个回答
1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.