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

时间:2011-08-07 18:51:55

标签: .net vb.net excel excel-vba border 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

请帮助..!

我是Vb.net的新手!

4 个答案:

答案 0 :(得分: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

删除单元格和单元格之间的边框(通过xlInsideHorizontalxlInsideVertical)。如果您需要对角线边框,请添加xlDiagonalDownxlDiagonalUp

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

For Each border in range.Borders
    border.LineStyle = Excel.XlLineStyle.xlLineStyleNone
Next

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

修改

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

range.Borders.LineStyle = Excel.XlLineStyle.xlLineStyleNone

答案 1 :(得分:4)

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

答案 2 :(得分:1)

检查NamedRange.BorderAround Method

Dim range As Excel.Range = sheet.Range("A2:K100")
range.BorderAround(Excel.XlLineStyle.xlLineStyleNone, Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, missing)
欢呼,祝你好运!

答案 3 :(得分:1)

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

整张纸张使用......

With .Cells
       .Borders.LineStyle = xlLineStyleNone
End With

对于一个范围,只需替换.Cells酌情