2013-06-14 2 views
0

저는 Visual Basic에서 초보자이며 Excel 파일에서 일부 작업을 수행하는 단순한 응용 프로그램을 작성하려고합니다.Visual Basic - Excel 셀의 테두리 속성

시트의 셀 테두리 속성을 편집하고 싶습니다. 일부 셀 (예 : 아래쪽 테두리 또는 위쪽 테두리)의 분리 된 테두리의 무게와 색을 편집해야합니다.

Ifound 웹에 몇 가지 흥미로운 자원 : http://www.functionx.com/vbaexcel/cells/Lesson4.htm Border around each cell in a range http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/93bb7ff7-0aed-4ce1-adca-aabde5fc3c2c

어쨌든 불가능하다 나에게 제안 예를 따르십시오. 이 내 코드의 추출물 :

Public Class mytest 
Dim oExcel As Object 'Oggetto per la gestione del file Excel 
Dim oBook As Object 'Oggetto per la gestione del file Excel 
Dim page As Integer = 1 'Indice per la gestione dei fogli Excel 
.... 

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
    'Creazione nuovo workbook in Excel 
    oExcel = CreateObject("Excel.Application") 
    oBook = oExcel.Workbooks.Add 

    'Add data to cells of the first worksheet in the new workbook 

    'Apertura file in lettura 
    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("input.csv") 
     MyReader.TextFieldType = FileIO.FieldType.Delimited 
     'Imposto il carattere di separazione tra i campi 
     MyReader.SetDelimiters(";") 

     'Creo stringa lettura righe 
     Dim currentRow As String() 

     'Leggo 1 volta per saltare 
     currentRow = MyReader.ReadFields() 

     'Fino alla fine del file 
     While Not MyReader.EndOfData 
      'Mostra riga nella label 
      lblShowElab.Text = page 
      Try 
       'Formatto i fogli 
       oBook.Worksheets(page).Range("A1:B1").Merge() 
       oBook.Worksheets(page).Range("A2:B2").Merge() 
    ... 

       oBook.Worksheets(page).Range("B2").Borders(xlEdgeRight).LineStyle = xlContinuous 
       oBook.Worksheets(page).Range("B2").Borders(xlEdgeRight).Weight = xlThin 

       'Leggo riga per riga 
       currentRow = MyReader.ReadFields() 
       'Inserisco i campi di ogni riga nella cella voluta 
       oBook.Worksheets(page).Range("F2").Value = currentRow(14) 
       oBook.Worksheets(page).Range("A5").Value = currentRow(12) 
       ... 
       'Incremento la pagina 
       page = page + 1 
       'Se la pagina e' maggiore di 3 la devo creare 
       If page > 3 Then 

oBook.Worksheets.Add(After:=oBook.Worksheets(oBook.Worksheets.Count)) 
       End If 

      Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException 
       MsgBox("Line " & ex.Message & "is not valid and will be skipped.") 
      End Try 
     End While 
     lblShowElab.Text = "Elaborazione Terminata" 
    End Using 
    'Salva il Workbook ed esce da Excel 
    oBook.SaveAs("output.xlsx") 
    oExcel.Quit() 
End Sub 
End Class 

명령 oBook.Worksheets (페이지) .Range ("B2") 테두리 (xlEdgeRight) .LineStyle = xlContinuous oBook.Worksheets (페이지) .Range. ("B2"). 테두리 (xlEdgeRight) .Weight = xl 내Visual Studio에서 xlEdgeRight, xlContinuous, xlEdgeRight, xlThin 변수를 인식하고 표시하지 않기 때문에 나를 위해 작동하지 않으며 이것을 선언합니다.

이 쉼표는 인터넷에서 발견되는 모든 예에서 공통적으로 사용되는 이유는 무엇입니까? 선언 할 라이브러리 나 네임 스페이스를 놓친 것일까? 내가 필요한 것?

누군가 나를 도울 수 있기를 바랍니다. 감사합니다.

답변

1

xlEdgeRight, xlContinuous, xlEdgeRight, xlThin 등의 모든 상수는 정수입니다.

값을 찾아 응용 프로그램에서 사용해야합니다.

이상한 점은 응용 프로그램에 많은 상수를 작성하여 명명 된 버전을 계속 사용할 수 있으므로 코드를 더 쉽게 이해할 수 있습니다.

다음 페이지는 모든 엑셀 상수와 그 값을 나열합니다. http://www.smarterdatacollection.com/Blog/?p=374 특정 Excel 버전과 연결되어 있지 않다고 가정합니다. 그러나 해당 버전이 있으면 해당 버전을 찾아야합니다.

+0

Excels VBA 편집기의 가장 빠른 방법은 즉시 (Ctrl + G) 창에서? xlEdgeRight를 실행하거나 개체 브라우저 (f2)에서 검색하는 것입니다. –

+0

감사합니다. 어쨌든 나는 해결책을 찾을 수 없었다. – Fedro

관련 문제