[英]EPPlus Changing Border Color of cells
I'm trying to change the cell border color on a selected range. 我正在尝试更改所选范围内的单元格边框颜色。 Couldn't find any other styles for cell borders other than for the weights of the borders as follows:
除了边框的权重之外,找不到任何其他单元格边框样式,如下所示:
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
If you want to sent border colors on different parts of the cells you can do it like this: 如果要在单元格的不同部分发送边框颜色,可以这样做:
range.Style.Border.Top.Color.SetColor(Color.Red);
range.Style.Border.Bottom.Color.SetColor(Color.Green);
range.Style.Border.Left.Color.SetColor(Color.Blue);
range.Style.Border.Right.Color.SetColor(Color.Yellow);
SetColor
can take any kind of System.Drawing.Color
. SetColor
可以采用任何类型的System.Drawing.Color
。
您可以使用此代码更改边框样式和颜色
range.Style.Border.BorderAround(ExcelBorderStyle.Medium, System.Drawing.Color.Blue);
using (ExcelRange range = worksheet.Cells["A1:H1"])
{
range.Style.Font.Bold = true;
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
range.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
range.Style.Fill.BackgroundColor.SetColor(Color.White);
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
range.Style.Border.Top.Color.SetColor(Color.Red);
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
range.Style.Border.Left.Color.SetColor(Color.Green);
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
range.Style.Border.Right.Color.SetColor(Color.Green);
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
range.Style.Border.Bottom.Color.SetColor(Color.Green);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.