[英]How to remove borders from cells in a range in Excel using VB.net?
實現目標:消除范圍單元格中的邊界。
我有 :
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 的新手!
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
移除單元格周圍和單元格之間的邊框(通過xlInsideHorizontal
和xlInsideVertical
)。 如果您需要對角線邊框,請包括xlDiagonalDown
和xlDiagonalUp
。
好的,上面的代碼非常冗長。 以下也應該這樣做:
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
Range("A2:K100").Borders.LineStyle = xlNone
為什么所有的答案都如此復雜?
對於整個工作表使用...
With .Cells
.Borders.LineStyle = xlLineStyleNone
End With
對於范圍,只需根據需要替換 .Cells
Dim range As Excel.Range = sheet.Range("A2:K100")
range.BorderAround(Excel.XlLineStyle.xlLineStyleNone, Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, missing)
歡呼,祝你好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.