Global It Leader!!



 
 

VB VB 에서 Exel 읽고 쓰기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 8,539회 작성일 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 오피스팁에서 이동 됨]

댓글목록

등록된 댓글이 없습니다.

전체 440
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
220 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6709 06-25
219 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7470 06-25
218 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8034 06-25
217 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13006 06-24
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8540 06-24
215 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9232 06-17
214 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 24956 07-22
213 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9923 07-21
212 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8413 07-21
211 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8726 07-21
210 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8114 07-20
209 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10037 07-15
208 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8111 07-14
207 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7422 07-14
206 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8898 07-13
205 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8963 07-13
204 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7569 07-08
203 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7252 07-08
202 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8599 07-08
201 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8091 07-08