[英]How to get borders/box around a range in Excel using EPPlus in C#
Below code generates borders for all cells within the range[2, 2, 5, 11], but I want only border around the range like a box.下面的代码为范围 [2, 2, 5, 11] 内的所有单元格生成边框,但我只想要像框一样的范围周围的边框。
var FirstTableRange = wsMyWorkSheet.Cells[2, 2, 5, 11];
FirstTableRange.Style.Border.Top.Style = ExcelBorderStyle.Thick;
FirstTableRange.Style.Border.Left.Style = ExcelBorderStyle.Thick;
FirstTableRange.Style.Border.Right.Style = ExcelBorderStyle.Thick;
FirstTableRange.Style.Border.Bottom.Style = ExcelBorderStyle.Thick;
Thanks in advance.提前致谢。
Below code generates borders around the range specified.下面的代码在指定范围周围生成边框。
var FirstTableRange = wsMyWorkSheet.Cells[2, 2, 5, 11];
FirstTableRange.Style.Border.BorderAround(ExcelBorderStyle.Thick);
If you write the code as in my question, it will generate borders for each cell within the range[2, 2, 5, 11] but not around the range.如果您按照我的问题编写代码,它将为范围 [2, 2, 5, 11] 内但不在该范围内的每个单元格生成边框。
不确定你是否已经弄清楚了,但这里是你如何在一个范围周围放置边框:
range.Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thick);
You can use the following line to do this:您可以使用以下行来执行此操作:
Range("A1:C10").Borders.LineStyle = xlContinuous
Adapt this to your code above and it should work将此适应您上面的代码,它应该可以工作
EDIT : The above code is actually to put a border around every cell in the range and I believe I have misunderstood your question and what you actually want is a border around the range itself.编辑:上面的代码实际上是在范围内的每个单元格周围放置一个边框,我相信我误解了你的问题,而你真正想要的是范围本身周围的边框。
To do this than use this:为此,请使用以下命令:
Worksheets("Sheet1").Range("A1:D4").BorderAround _
ColorIndex:=3, Weight:=xlThick
This is just an example, change the color to your desired color and thinkness too or just simply keep it as default.这只是一个例子,也可以将颜色更改为您想要的颜色和想法,或者只是将其保留为默认值。
EDIT : I have found the following on the internet.编辑:我在互联网上找到了以下内容。 Take a look and see if your doing it as the video explains: Click here
看看你是否按照视频中的解释去做: 点击这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.