none
How to draw table in excel

    Question

  • Hi all. i can use vb.net to insert data into excel but i dont know how to insert table ?

    Ex:  id       name
           01      jack
           02      luchy

       i want to insert table with it.
       what should i do ?
    Friday, August 07, 2009 7:04 AM

Answers

  • Hi Sopheak,

        I think i got the effect that you want.
        Please add the following code in the method
        With oSheet
            .Range(.Cells(1, 1), _
                .Cells(3, 2)).Borders.LineStyle = Excel.XlBorderWeight.xlHairline
        End With

    Hope this helps.

    Regards
    Jeff Shan
    • Marked as answer by Sopheak.KH Wednesday, August 12, 2009 1:26 PM
    Wednesday, August 12, 2009 7:20 AM

All replies

  • This link has threads covering "excel automation".  Take your pick of them and use the code you find in them to do the things you want:

    http://social.msdn.microsoft.com/Search/en-US/?Refinement=112&query=automate%20excel&rq=meta:Search.MSForums.ForumID(0f60fa48-1ceb-41ee-a10a-0dfcee7e19bd)&rn=Visual+Basic+General+Forum



    Doug

    SEARCH ... then ask
    Friday, August 07, 2009 7:18 AM
  • Hi Sopheak,

     

    Thanks for using Microsoft MSDN forums!

    I read your post,  and think that you may need the following information
    http://www.jkp-ads.com/articles/Excel2007TablesVBA.asp


    Hope this helps
    Regards
    Jeff Shan
    Monday, August 10, 2009 11:49 AM
  • thz Jeff Shan for ur link, but i cant underdtand of vba code.
    i 1 2 use vb.net code. can u help me ?
    Tuesday, August 11, 2009 7:02 AM
  • Hi Sopheak,

        Here is an example you can refer to:

        Sub WriteExcel()
            Dim oXL As Excel.Application
            Dim oWB As Excel.Workbook
            Dim oSheet As Excel.Worksheet
            Dim oRng As Excel.Range
            ' Start Excel and get Application object.
            oXL = CreateObject("Excel.Application")
            oXL.Visible = True
            ' Get a new workbook.
            oWB = oXL.Workbooks.Add
            oSheet = oWB.ActiveSheet
            ' Add table headers going cell by cell.
            oSheet.Cells(1, 1).Value = "id"
            oSheet.Cells(1, 2).Value = "name"
            ' Format A1:B1 as bold, vertical alignment = center.
            With oSheet.Range("A1", "B1")
                .Font.Bold = True
                .VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
            End With
            ' Create an array to set multiple values at once.
            Dim saNames(2, 2) As String
            saNames(0, 0) = "01"
            saNames(0, 1) = "jack"
            saNames(1, 0) = "02"
            saNames(1, 1) = "luchy"
    
            ' Fill A2:B3 with an array of values
            oSheet.Range("A2", "B3").Value = saNames
            ' Make sure Excel is visible and give the user control
            ' of Excel's lifetime.
            oXL.Visible = True
            oXL.UserControl = True
            ' Make sure that you release object references.
            oRng = Nothing
            oSheet = Nothing
            oWB = Nothing
            oXL.Quit()
            oXL = Nothing
        End Sub

    Hope this helps

    Regards
    Jeff Shan
     

    Tuesday, August 11, 2009 11:04 AM
  • I use this code but it still cant draw table with it.it has only data.
    i use office 2007.
    can u tell me some reason.
    thz
    Wednesday, August 12, 2009 1:50 AM
  • Hi Sopheak,

        I think i got the effect that you want.
        Please add the following code in the method
        With oSheet
            .Range(.Cells(1, 1), _
                .Cells(3, 2)).Borders.LineStyle = Excel.XlBorderWeight.xlHairline
        End With

    Hope this helps.

    Regards
    Jeff Shan
    • Marked as answer by Sopheak.KH Wednesday, August 12, 2009 1:26 PM
    Wednesday, August 12, 2009 7:20 AM
  • nth to sayjust thz alots for ur code.
     :D

    Wednesday, August 12, 2009 1:33 PM
  • thz FlipKrnjic
     but i dont know where can i get gembox for free ?
    can u tell me ?
    • Edited by Sopheak.KH Thursday, August 13, 2009 9:40 AM
    Thursday, August 13, 2009 9:29 AM
  • U can go to mininova.org and search there. There many free program!
    Thursday, August 13, 2009 9:41 AM