Results 1 to 8 of 8

Thread: [Resolved][2005] Listview to Excel

  1. #1

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    [Resolved][2005] Listview to Excel

    Hi, I need to populate a data from a listview into excel app, the thing is what could be the specific namespace that I will use?

    Can someone give me a little bit of an idea on how to implement this? Btw, when I add a reference in the COM tab I get a list of component name like MS Excel 5.0/11.0 Object Library, MS Office 10.0/11.0 Object Library.


    To add information I use Office 2003 standard edition.


    Thanks.
    Last edited by fret; Feb 14th, 2008 at 09:32 PM.

  2. #2
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: [2005] Listview to Excel

    Component:.MS Excel 11.0 object Library

    NameSpace : Imports Microsoft.Office.Interop
    Visual Studio.net 2010
    If this post is useful, rate it


  3. #3
    New Member
    Join Date
    Feb 2008
    Posts
    1

    Re: [2005] Listview to Excel

    AH HEHE HE
    You need to be a noob like me
    Learn to use Excel tard

  4. #4
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: [2005] Listview to Excel

    Here the simple way to export the listview to EXCEL.
    While working with excel object, you have to be carefull..
    Check whether the system having Excel...
    Create Excel Object @ runtime.
    Quit the objects properly.

    Code:
        Dim xlApp As Object, xlBook As Workbook, xlsheet As Object, i As Integer
        Dim s As String
        Dim lst As ListItem, lst1 As ListSubItem, row As Integer, col As Integer
        
        Set xlApp = New Excel.Application
        Set xlBook = xlApp.Workbooks.Add 'creates a blank workbook
        Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
        
        row = 1
        col = 1
      'First retrieve the column header
        For i = 1 To ListView1.ColumnHeaders.Count
            xlsheet.Cells(row, col) = ListView1.ColumnHeaders(I)
            col = col + 1
        Next
        col = 1
        row = row + 1
        For Each lst In ListView1.ListItems
            col = 1
            xlsheet.Cells(row, col) = lst.Text
            col = col + 1
            For Each lst1 In lst.ListSubItems
                xlsheet.Cells(row, col) = lst1.Text
                col = col + 1
            Next
            row = row + 1
        Next
        xlBook.Close savechanges:=True, FileName:="c:\temp\test.xls"
        xlApp.Quit
    Visual Studio.net 2010
    If this post is useful, rate it


  5. #5

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: [2005] Listview to Excel

    Thanks for your reply vijy, however there's something wrong when I try to add the COM object(MS Excel 11.0 Object Library) as what you've said, it gives a warning message of "Cannot find wrapper assembly for type library 'Excel'" and "The referenced component 'Excel' could not be found". Also when I try to add the namespace it gives only

    vb.net Code:
    1. Imports Microsoft.Office.Core

    Is there something wrong with my COM Objects?




    Again thanks.

  6. #6
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] Listview to Excel

    I used the function from here, and it worked a treat.
    It should help you with what you're looking for.

    http://www.osix.net/modules/article/?id=746

  7. #7
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Listview to Excel

    Check out my post in the codebank for creating an excel file from a datatable. It could be easily modified to work with your listview data.
    http://www.vbforums.com/showthread.php?t=483241
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  8. #8

    Thread Starter
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: [2005] Listview to Excel

    Thanks guys, sorry for the late reply.

    After a couple of reading I found out this thread is related to mine, and now I manage to solve about my COM Objects updated by downloading, and for all reference guide that you've given to me I'm on the process now.


    Cheers, fret.

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