Link to home
Start Free TrialLog in
Avatar of wally_davis
wally_davisFlag for United States of America

asked on

How do you Export Data from a ListViewItem to Excel using VB.NET?

How do you Export Data from a ListViewItem to Excel using VB.NET?

I need a way to export all of the Data into Excel, along with Formatting the Row Headers, etc.
If someone has the code or a great resource to walk you through this process I would be most grateful.

Thanks for your time,
Wallace
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wally_davis

ASKER

Hi James,
I have a Button control click event that I want to use.
How could I pass the lvName as DataType "ListView" using what I currently have now?
"Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click"

Thank you!!
It looks like I would use what you have and then make a call to it right?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, I'm geting close here.

I did what you said but type this instead because it said "ListView1 was not declared" and "ListView is a type and cannot be used as an expression":

I typed:
Dim lvName as New ListView ' <-- in order to satisfy the next line.
Call ExportToExcel(lvName) ' and I also tried (Sender) but once it hits here it opens the Excel Spreadsheet but then nothing gets written to it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Duh, don't I feel stupid. Yes, I have an LVI with the Design name of lstQueryResults. I'm adding that in right now and will test again.
I'm impressed. Your a God send. I ran it and it worked Purrrfectly...!
Your code, compared to that of others (and not to take away from other good and great programmers),  is very short (the way code should be written) and works like a champ.
People like you inspire me to want to become better at programming. I mean, this is great. I can step through the code, and watch how it works, etc.

Thank you James. P.S. Any good books or websites you could recommend would be wonderful. I'm always looking for additional resources to better myself.
Sincerely,
Wally
Well it's not the complex code that works better than the easy one. I always try to improve my code (new function, functionalities, etc) and I like the code easy to understand and debug.

I personally don't like books! You spend a lot of time reading and you read things that you already know, so I try to go to some web sites and read then update. I like:

https://www.experts-exchange.com ' I subscribe the questions that I like to know and I follow the discussion
www.codeproject.com
msdn2.microsoft.com 'Technical articles, msdn magazine, etc.

and some times:
www.planetsourcecode.com

Glad i could help you and thanks for the grade and for the words!