边框可以通过编程方式设置,直接调用工作表API,也可以通过执行操作来设置。
当前版本的ReoGrid支持以下边框样式:

边框样式定义为BorderLineStyle枚举。
边框必须围绕一个区域设置,即使该区域只包含一个单元格。要指定边框位置,请使用BorderPositions枚举及其二进制组合值。

要在工作表中为特定区域应用边框,使用SetRangeBorders方法:
import dotNet.ReoGrid;
var sheet1 = reoGridControl.CurrentWorksheet;
// 为指定区域外部应用自定义样式的边框
sheet1.SetRangeBorders("B3:D7", ReoGrid.BorderPositions.Outside, ReoGrid.RangeBorderStyle(
Color = ReoGrid.Graphics.SolidColor.Magenta,
Style = ReoGrid.BorderLineStyle.BoldSolid
));

要通过可撤销的操作在区域内应用边框,使用以下方法:
reoGridControl.DoAction(reoGridControl.CurrentWorksheet,
ReoGrid.Actions.SetRangeBorderAction(
ReoGrid.RangePosition(2, 1, 5, 3),
ReoGrid.BorderPositions.All,
ReoGrid.RangeBorderStyle({
Color = ReoGrid.Graphics.SolidColor.Red,
Style = ReoGrid.BorderLineStyle.Dashed
})
)
);

要获取工作表中特定区域应用的边框详细信息,使用GetRangeBorders方法:
// 获取指定区域的边框信息
var borderInfoSet = sheet1.GetRangeBorders("A1:D5");
GetRangeBorders方法分析指定区域内的边框并返回一个RangeBorderInfoSet。该集合包含在整个区域内一致应用的边框样式实例。
要识别区域内样式不同的边框,检查RangeBorderInfoSet的NonUniformPos属性。该属性突出显示与主要样式不同的边框位置。
要枚举指定区域内的所有边框,使用工作表的IterateBorders方法。
IterateBorders(RowOrColumn direction, RangePosition range, Func<int, int, int, RangeBorderStyle, bool> iterator);
direction - 指定迭代模式:
RowOrColumn.Row 迭代所有水平边框RowOrColumn.Column 迭代所有垂直边框RowOrColumn.Both 迭代所有边框,包括行和列range: 要迭代边框的目标区域iterator: 用户代码提供的回调函数,用于检查从工作表中检索的所有边框。该函数接受以下参数:
int Row: 边框所在的行号int Column: 边框所在的列号int Span: 从此起始位置开始具有相同样式的连续边框数量RangeBorderStyle - 包含边框的颜色和样式详情bool 返回值: 返回true将继续迭代,返回false将终止迭代过程例如,遍历所有水平边框,如果单元格位置有边框,则将单元格背景标记为红色:
// 在指定区域内设置水平内部边框
sheet1.Ranges["C3:F10"].BorderInsideHorizontal = ReoGrid.RangeBorderStyle.BlackSolid;
// 在整个工作表区域内迭代水平边框
sheet1.IterateBorders(ReoGrid.RowOrColumn.Row, ReoGrid.RangePosition.EntireRange, function(r, c, span, border) {
// 为有边框的单元格应用红色背景
sheet1.Cells[r, c].Style.BackColor = ReoGrid.Graphics.SolidColor.LightCoral;
return true; // 继续迭代
});

迭代所有垂直边框:
// 设置边框
sheet1.Ranges["C3:F10"].BorderInsideVertical = ReoGrid.RangeBorderStyle.BlackSolid;
// 迭代边框
sheet1.IterateBorders(ReoGrid.RowOrColumn.Column, ReoGrid.RangePosition.EntireRange, function(r, c, span, border) {
sheet1.Cells[r, c].Style.BackColor = ReoGrid.Graphics.SolidColor.LightCoral;
return true;
});

迭代所有边框,包括行和列边框:
// 设置边框
sheet1.Ranges["C3:F10"].BorderOutside = ReoGrid.RangeBorderStyle.BlackBoldSolid;
sheet1.Ranges["C3:F10"].BorderInsideHorizontal = ReoGrid.RangeBorderStyle.BlackSolid;
sheet1.Ranges["C3:F10"].BorderInsideVertical = ReoGrid.RangeBorderStyle.BlackDotted;
// 迭代边框
sheet1.IterateBorders(ReoGrid.RowOrColumn.Both, ReoGrid.RangePosition.EntireRange, function(r, c, span, border) {
sheet1.Cells[r, c].Style.BackColor = ReoGrid.Graphics.SolidColor.LightCoral;
return true;
});

要从工作表中移除边框,可以使用RemoveRangeBorders方法:
// 从工作表中移除指定区域的所有边框
sheet1.RemoveRangeBorders(ReoGrid.RangePosition(2, 1, 5, 1), ReoGrid.BorderPositions.All);
或者,将边框样式设置为RangeBorderStyle.Empty也可以有效移除边框:
// 将指定区域的边框样式设置为'Empty'以移除边框
sheet1.SetRangeBorders(ReoGrid.RangePosition(2, 1, 5, 3), ReoGrid.BorderPositions.All, ReoGrid.RangeBorderStyle.Empty);
要通过可撤销的操作移除边框,可以如下使用DoAction方法:
reoGridControl.DoAction(reoGridControl.CurrentWorksheet,
ReoGrid.Actions.RemoveRangeBorderAction(
ReoGrid.RangePosition(2, 1, 5, 1),
ReoGrid.ReoGridBorderPos.All
)
);
可以通过调用Undo方法撤销此操作:
// 撤销边框移除操作
reoGridControl.Undo();