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.
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.
不确定你是否已经弄清楚了,但这里是你如何在一个范围周围放置边框:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.