웹프로그래밍

Global It Leader!!


컴퓨터언어


 
 

VB VB 에서 Exel 읽고 쓰기

페이지 정보

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

댓글목록

등록된 댓글이 없습니다.

전체 441
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
221 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7119 06-25
220 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7936 06-25
219 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8473 06-25
218 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13429 06-24
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8964 06-24
216 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9645 06-17
215 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 25523 07-22
214 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10310 07-21
213 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8790 07-21
212 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9142 07-21
211 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8556 07-20
210 VB no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10446 07-15
209 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8539 07-14
208 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7833 07-14
207 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9398 07-13
206 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9422 07-13
205 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8007 07-08
204 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7653 07-08
203 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9042 07-08
202 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8535 07-08