Results 1 to 3 of 3

Thread: [RESOLVED] Export to excel

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    39

    Resolved [RESOLVED] Export to excel

    Hi, I'm having problems exporting data from a listview control to excel

    for example we have item "serial" with the child items "pass value".

    PHP Code:
    serial value1 value 2 value 3 value 4 |
    -------------------------------------------
    serial |    a     |     b     |    c      |     d     
    PHP Code:
     For 1 To ListView1.listitems.count
            With xlSheet
            
    'serial
                .Cells(init_row + i + 1, init_col + 1) = ListView1.listitems.Item(i)
                For j = 1 To ListView1.ColumnHeaders.count - 1
                    '
    pass value
                    
    .Cells(init_row 1init_col j) = ListView1.listitems.Item(i).SubItems(j)
                
    Next j
            End With
        Next
        init_row 
    init_row 
    PHP Code:
    How to arrange the data in the required format?

    serial   a  |     |     |  |    |    |
              |-------------------------
              | 
    c  |     |     | d  |    |    |
    --------------------------------- 

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Export to excel

    You need to first loop thru column headers and when it's done thru the list of items.
    So, move "For j = 1 To ListView1.ColumnHeaders.count - 1" loop out of the main loop; then start the main loop "For i = 1 To ListView1.listitems.count".
    Code:
    For j = 1 To ListView1.ColumnHeaders.count - 1
        '...
    Next j
    
    For i = 1 To ListView1.listitems.count
        '...
    Next i

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2010
    Posts
    39

    Re: Export to excel

    Thanks but I've gone the way of outputting plain text files in HTML code and save it as .xls and spreadsheet program like Kingsoft ET is able to interpret all those HTML tags like <tr>,<td> and <table>. This way is so much easier. I wonder if this is a correct way but it provides the solution I want.

    Quote Originally Posted by RhinoBull View Post
    You need to first loop thru column headers and when it's done thru the list of items.
    So, move "For j = 1 To ListView1.ColumnHeaders.count - 1" loop out of the main loop; then start the main loop "For i = 1 To ListView1.listitems.count".
    Code:
    For j = 1 To ListView1.ColumnHeaders.count - 1
        '...
    Next j
    
    For i = 1 To ListView1.listitems.count
        '...
    Next i

Tags for this Thread

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