Global It Leader!!



 
 

VB VB 에서 Exel 읽고 쓰기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 8,537회 작성일 10-06-24 11:25

본문

Excel 파일의 내용을 Grid 컨트롤로 읽고,

Grid의 내용을 Excel 파일로 저장하는 소스입니다.


먼저 VB 메뉴  프로젝트  --> 참조 에서

Microsoft Excel Object  를 포함시키세요...


'------------------------------------------------------------------------

'파일 읽기

'------------------------------------------------------------------------

Private Sub ReadFile(FileName$)


    Dim exl As Excel.Application

    Dim sheet As Excel.Worksheet

    Dim Data(10)

    Dim i%

   

    If Dir(FileName) = "" Then Exit Sub

   

    Set exl = New Excel.Application

    exl.Workbooks.Open FileName

    Set sheet = exl.Workbooks(1).Sheets(1)

   

    With grd

        For i = 1 To .Rows - 1

            .TextMatrix(i,1) = sheet.Cells(i + 1, 1)

        Next i

    end With

   

    exl.Workbooks(1).Close

    Set sheet = Nothing

    Set exl = Nothing

   

End Sub


'------------------------------------------------------------------------

'파일 저장

'------------------------------------------------------------------------

Private Sub SaveExcel(FileName As String, grd As VSFlexGrid)

On Error Resume Next

    Dim exl As Excel.Application

    Dim sheet As Excel.Worksheet

   

    Dim i&, j%

   

    Screen.MousePointer = 11

   

    Set exl = New Excel.Application

   

    exl.Workbooks.Add  'Open  .Workbooks.Open FileName

   

    Set sheet = exl.Workbooks(1).Sheets(1)

   

    'sheet.Cells.Select

    'exl.Selection.NumberFormatLocal = "@"

   

    sheet.Columns(1).Select

    exl.Selection.NumberFormatLocal = "0_ "

   

    sheet.Columns(2).Select

    exl.Selection.NumberFormatLocal = "@"

   

    sheet.Columns(3).Select

    exl.Selection.NumberFormatLocal = "@"

   

    sheet.Columns(4).Select

    exl.Selection.NumberFormatLocal = "0.0000_ "

   

    sheet.Columns(5).Select

    exl.Selection.NumberFormatLocal = "0.0000_ "

   

    sheet.Columns(6).Select

    exl.Selection.NumberFormatLocal = "0.0000_ "

   

    exl.Range(sheet.Cells(1, 1), sheet.Cells(1, grd.Cols)).Select

    With exl.Selection.Interior

        .ColorIndex = 15

        .Pattern = xlSolid

    End With

   

    exl.Selection.NumberFormatLocal = "@"

   

    With grd

        For i = 0 To .Rows - 1

            For j = 0 To .Cols - 1

                sheet.Cells(i + 1, j + 1) = .TextMatrix(i, j)

                '.Cell(flexcpChecked, i, j) = IIf(sheet.Cells(i + 1, j + 1) = "1", flexChecked, flexUnchecked)

            Next j

        Next i

    End With

   

    Screen.MousePointer = 0

   

    exl.Workbooks(1).SaveAs FileName

    exl.Workbooks(1).Close

    Set sheet = Nothing

    Set exl = Nothing

   

End Sub

[이 게시물은 오원장님에 의해 2013-02-28 16:42:35 오피스팁에서 이동 됨]

댓글목록

등록된 댓글이 없습니다.

전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
55 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6321 12-16
54 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4449 11-14
53 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8855 11-05
52 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4623 10-24
51 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7110 10-24
50 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4661 07-26
49 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4743 03-09
48 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4910 03-09
47 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10842 06-30
46 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6707 06-25
45 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7468 06-25
44 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8032 06-25
43 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13003 06-24
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8538 06-24
41 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9230 06-17
40 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 24952 07-22
39 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9921 07-21
38 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8410 07-21
37 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8724 07-21
36 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8112 07-20