CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2002
    Location
    Bangalore
    Posts
    42

    Lightbulb Exporting data from Grid Control to Excell

    Hello Gurus,

    I have a small problem.

    I am using a grid control in my vb project. Which has 5 columns and
    some rows. Now I would like to insert these values from the grid
    into a new microsoft excell sheet from vb by clicking a button.
    The columns and rows should come as it is there in the grid.

    I would like to have the code for this problem.

    Can anybody help me...?

    Thank you

    Regards

    Benny
    Benny C A
    Al Ain, UAE

  2. #2
    Join Date
    Mar 2004
    Posts
    2
    Hi friends,

    I've met the same situation. Has anyone got any suggestion for the problem?

    Thanks a lot
    Khoa

  3. #3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651
    Look here:

    http://support.microsoft.com/default...b;EN-US;247412

    and here:

    http://support.microsoft.com/default...;EN-US;Q178510


    I have also posted quite a few posts and responses regarding Excel and VB 6. Do a search for Excel or under my UserName to find them.
    I'd rather be wakeboarding...

  4. #4
    Join Date
    Mar 2004
    Posts
    2
    It helps a lot!

    Thanks Malleyo!
    Khoa

  5. #5
    Join Date
    Mar 2004
    Location
    Aurangabad (MS) INDIA
    Posts
    8
    Its Simple !
    'Add refrence File Scripting runtime,microsoft excel etc.
    'Do minor correction as required!
    Dim Fsys As New Scripting.FileSystemObject
    Dim XlApp As excel.Application
    c=5 'Column
    r=5 'Row
    Set OStream = Fsys.OpenTextFile("c:\Data.xls", ForWriting, True)
    If Err Then
    OStream.Close
    Err.Clear
    Exit Sub
    End If

    'Take data into array Grid() or directly maniuplate grid control

    For r=1 to 5 ' Read rows
    For c=i to 5 'read column
    ostream.write grid(i,j)
    next c
    next r
    ostream.close

    Set Wb = XlApp.Workbooks.Open("C:\Data.txt")
    XlApp.WindowState = xlNormal
    XlApp.Application.Visible = True
    XlApp.ScreenUpdating = True


    'This will solve ur problem
    Sunil
    09823214545

  6. #6
    Join Date
    Oct 2003
    Location
    Philadelphia, PA
    Posts
    167
    What about just conversting to CSV or another text format and loading from there?
    Mike Dershowitz
    [email protected]
    www.lexientcorp.com

  7. #7
    Join Date
    Mar 2004
    Location
    Aurangabad (MS) INDIA
    Posts
    8
    'Do slight modification in the program
    Dim Fsys As New Scripting.FileSystemObject
    Dim XlApp As excel.Application
    c=5 'Column
    r=5 'Row
    Set OStream = Fsys.OpenTextFile("c:\Data.xls", ForWriting, True)
    If Err Then
    OStream.Close
    Err.Clear
    Exit Sub
    End If

    'Take data into array Grid() or directly maniuplate grid control

    For r=1 to 5 ' Read rows
    For c=i to 5 'read column
    ostream.write grid(i,j)
    ostream .write vbtab ' for Tab demilited txt file
    ostream.write "," for CSV file
    "You can insert any character to separate the data in the file 'using above statement like (tab,comma ,space or any other special character) and finally open this file using Excel"

    next c
    next r
    ostream.close

    Set Wb = XlApp.Workbooks.Open("C:\Data.xls")
    XlApp.WindowState = xlNormal
    XlApp.Application.Visible = True
    XlApp.ScreenUpdating = True

    I think this answers ur question

    Regards,
    Sunil

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured