code

VB.net 을 사용하여 Excel의 범위에 있는 셀에서 테두리를 제거하는 방법은 무엇입니까?

starcafe 2023. 6. 17. 09:33
반응형

VB.net 을 사용하여 Excel의 범위에 있는 셀에서 테두리를 제거하는 방법은 무엇입니까?

목표 달성:범위의 셀에 테두리가 있는 경우 테두리를 제거합니다.

다음이 있습니다.

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

범위는 그냥 대체합니다.해당하는 셀

명명된 범위를 선택합니다.테두리 둘레 메소드입니다.

Dim range As Excel.Range = sheet.Range("A2:K100")
range.BorderAround(Excel.XlLineStyle.xlLineStyleNone, Excel.XlBorderWeight.xlThin, Microsoft.Office.Interop.Excel.XlColorIndex.xlColorIndexAutomatic, missing)

환호와 행운을 빕니다!

언급URL : https://stackoverflow.com/questions/6974965/how-to-remove-borders-from-cells-in-a-range-in-excel-using-vb-net

반응형