如何使用VB.net从Excel中的单元格中删除边框?

Yug*_*dle 10 .net vb.net excel vba border excel-vba

旨在实现: 在范围单元格中删除边界.

我有 :

Dim range As Excel.Range = sheet.Range("A2:K100")
For Each cell In range
    // Some cells in the Range has borders
    // How to remove borders from cells in the range
Next cell
Run Code Online (Sandbox Code Playgroud)

请帮忙.. !

我是Vb.net的新手!

VVS*_*VVS 20

range.Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlLineStyleNone
range.Borders(Excel.XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlLineStyleNone
Run Code Online (Sandbox Code Playgroud)

删除单元格周围和单元格之间的边框(通过xlInsideHorizontalxlInsideVertical).如果你期望对角线边界,包括xlDiagonalDownxlDiagonalUp.

好的,上面的代码非常详细.以下也应该这样做:

For Each border in range.Borders
    border.LineStyle = Excel.XlLineStyle.xlLineStyleNone
Next
Run Code Online (Sandbox Code Playgroud)

请参阅:http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.borders.aspx

编辑:

在查看MSDN页面时,我想知道这个内核是否也可以这样做:

range.Borders.LineStyle = Excel.XlLineStyle.xlLineStyleNone
Run Code Online (Sandbox Code Playgroud)

  • 等等.. 一个班轮.. 就是我要找的.. **太棒了!!谢谢!!** (2认同)

Ste*_*tin 5

为什么所有的答案都如此复杂?

对于整张纸的使用...

With .Cells
       .Borders.LineStyle = xlLineStyleNone
End With
Run Code Online (Sandbox Code Playgroud)

对于范围,只需根据需要替换 .Cells


小智 5

Range(“ A2:K100”)。Borders.LineStyle = xlNone

  • 这是正确的答案。其他的则不必要地复杂。 (2认同)