|
-
Feb 13th, 2008, 04:28 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Feb 13th, 2008, 05:23 AM
#2
Fanatic Member
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

-
Feb 13th, 2008, 05:26 AM
#3
New Member
Re: [2005] Listview to Excel
AH HEHE HE
You need to be a noob like me
Learn to use Excel tard
-
Feb 13th, 2008, 05:32 AM
#4
Fanatic Member
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

-
Feb 13th, 2008, 07:57 PM
#5
Thread Starter
Hyperactive Member
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:
Imports Microsoft.Office.Core
Is there something wrong with my COM Objects?
Again thanks.
-
Feb 14th, 2008, 05:24 AM
#6
Hyperactive Member
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
-
Feb 14th, 2008, 01:34 PM
#7
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
-
Feb 14th, 2008, 09:31 PM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|