如何使用VB.net从Excel范围内的单元格中删除边框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6974965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove borders from cells in a range in Excel using VB.net?
提问by Yugal Jindle
Aim to Achieve:To get rid of borders if any in the cells of range.
实现目标:消除范围单元格中的边界。
I have :
我有 :
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
Please help.. !
请帮忙.. !
I am new to Vb.net !
我是 Vb.net 的新手!
回答by VVS
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
Removes the borders around the cells and between cells (via xlInsideHorizontaland xlInsideVertical). If you expect diagonal borders, include xlDiagonalDownand xlDiagonalUp.
移除单元格周围和单元格之间的边框(通过xlInsideHorizontal和xlInsideVertical)。如果您需要对角线边框,请包括xlDiagonalDown和xlDiagonalUp。
Okay, the above code was very verbose. The following should do it too:
好的,上面的代码非常冗长。以下也应该这样做:
For Each border in range.Borders
border.LineStyle = Excel.XlLineStyle.xlLineStyleNone
Next
See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.borders.aspx
请参阅:http: //msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.borders.aspx
EDIT:
编辑:
While looking over the MSDN page, I'm wondering if this one liner could do it too:
在查看 MSDN 页面时,我想知道这个班轮是否也可以做到:
range.Borders.LineStyle = Excel.XlLineStyle.xlLineStyleNone
回答by Unknown
Range("A2:K100").Borders.LineStyle = xlNone
Range("A2:K100").Borders.LineStyle = xlNone
回答by Steven Martin
why are all the answers so convoluted?
为什么所有的答案都如此复杂?
for the entire sheet use...
对于整个工作表使用...
With .Cells
.Borders.LineStyle = xlLineStyleNone
End With
for a range just replace .Cells as appropriate
对于范围,只需根据需要替换 .Cells
回答by Lucian
Check 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)
cheers and good luck!
欢呼,祝你好运!

