Solved

Convert Listview to excel file (vb6)

Posted on 2007-11-15
6
2,997 Views
Last Modified: 2008-02-01
Hi,
 How do I convert listview to excel file

Thx.
0
Comment
Question by:madmare
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20287715
use the following code

 Dim xlApp as Object,xlBook as Object,xlsheet as Object, i as Integer
   Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Open(App.path & "\ListBook1.xls") 'to open the workbook
    Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
For i=0 to List1.ListCount-1
    xlsheet.Cells(i,1)=List1.Items(i)
Next
xlBook.Close savechanges:=true
xlApp.Quit
0
 

Author Comment

by:madmare
ID: 20287749
in my listview I don't have the proporites "ListCount" & "Items"

I am useing VB6

0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20287764
Can you elaborate which control you are using and which development environment?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:madmare
ID: 20287864
I am using ListView object in VB6 windows application
0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20288086
'ok try this then
Dim xlApp As Object, xlBook As Object, xlsheet As Object, i As Integer
   Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Open(App.Path & "\ListBook1.xls") 'to open the workbook
    Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
For i = 0 To ListView1.ListItems.Count - 1
    xlsheet.Cells(i, 1) = ListView1.ListItems(i)
Next
xlBook.Close savechanges:=True
xlApp.Quit
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 20288455
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
    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
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question