User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 374,011 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,862 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 906 | Replies: 14 | Solved
Reply
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Export Data from listbox to Excel

  #1  
May 10th, 2008
hey I faced the interview Question -

Name Textbox
EMail Textbox
Mobile Textbox
Button-ADD

First he told me to add the three textboxes values into the listbox.
Its simple--I have done it.

Listbox1.items.add(me.textbox1.text & " " & me.textbox2.text & " " & me.textbox3.text)

Then he told me that draw one more button -PRINT & on PRINT Button click the listboxes
information are exported to EXCEL to the individual columns.
Means name in first column & email in second column & Mobile in Third Column.
Plz send me the coding of this bz I have no idea from where to start it.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Jogja
Posts: 2,330
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 9
Solved Threads: 204
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

Re: Export Data from listbox to Excel

  #2  
May 10th, 2008
Go to Project -> References -> Microsoft Excel 10.0 Object Library
Then add this following code :
  1. Dim MsExcel As Excel.Application
  2. Private Sub Command1_Click()
  3. MsExcel.Workbooks.Add
  4. MsExcel.Range("A1").Value = List1.List(0)
  5. MsExcel.Range("B1").Value = List1.List(1)
  6. MsExcel.Range("C1").Value = List1.List(2)
  7. MsExcel.Visible = True
  8. End Sub
  9.  
  10. Private Sub Command2_Click()
  11. With List1
  12. .AddItem (txtName.Text)
  13. .AddItem (txtEmail.Text)
  14. .AddItem (txtMobile.Text)
  15. End With
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19. Set MsExcel = CreateObject("Excel.Application")
  20. End Sub
Attached Images
File Type: jpg Export to Excel.JPG (79.3 KB, 6 views)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Re: Export Data from listbox to Excel

  #3  
May 11th, 2008
HI Jx_Man, I want the code in VB.net ,but its a Vb Code...Rite????????

i do the foll. steps--
Go to project-->Add Refernce->Microsoft Excel 11.0 Object Library

cz there is noo Microsoft Excel 10.0 Object Library in Vb.net

Plz tell me y there are two commands buttons in the code given as above--
I want just the one command button Print.

Where I have to write the above steps......on print_click

My code is as under---
Public Class Form2


Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
ListBox1.Items.Add(Me.txtname.Text & " " & Me.txtmail.Text & " " & Me.txtmob.Text & " " & Date.Now)
End Sub
Dim MsExcel As Excel.Application
Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click

End Sub
End Class
Reply With Quote  
Join Date: Nov 2007
Location: Jogja
Posts: 2,330
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 9
Solved Threads: 204
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

Re: Export Data from listbox to Excel

  #4  
May 11th, 2008
oh... i m so sorry...
yeah that codes for vb 6, but there are same code for vb.net.
this following code for vb.net.
  1. Dim MsExcel As Excel.Application
  2.  
  3. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. MsExcel = CreateObject("Excel.Application")
  5. End Sub
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. With ListBox1.Items
  8. .Add(txtName.Text)
  9. .Add(txtEmail.Text)
  10. .Add(txtMobile.Text)
  11. End With
  12. End Sub
  13.  
  14. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15. MsExcel.Workbooks.Add()
  16. MsExcel.Range("A1").Value = txtName.Text
  17. MsExcel.Range("B1").Value = txtEmail.Text
  18. MsExcel.Range("C1").Value = txtMobile.Text
  19. MsExcel.Visible = True
  20. End Sub
- button 1 for add item from textbox to listbox.
- button 2 to add all item in listbox to excel.
- Declare Dim MsExcel As Excel.Application in top of all event. don't declare it on event cause it be a global variable.
- You can modified it as u needed.
Last edited by Jx_Man : May 11th, 2008 at 5:32 am.
Attached Images
File Type: jpg Export to Excel .net.JPG (78.3 KB, 3 views)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Re: Export Data from listbox to Excel

  #5  
May 11th, 2008
hi Jx_Man,THX VERY VERY MUCH.
Hey if want also that when the record goes to excel,individual columns have name also like name,email,mobile.
then?????

Hey tell me one thing if u want,how u know so much of coding...like this question......this coding u done it by urself..........or thru book. Hey plz tell me also na,i will be very thankfull to you.
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 46
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Export Data from listbox to Excel

  #6  
May 11th, 2008
Jx_man probably knows it off the top of his head. He is the Don!
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Re: Export Data from listbox to Excel

  #7  
May 11th, 2008
ya he is,but i want only some tips so that i may be ............
Reply With Quote  
Join Date: Oct 2007
Location: Bristol, UK
Posts: 1,122
Reputation: majestic0110 is on a distinguished road 
Rep Power: 3
Solved Threads: 46
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Veteran Poster

Re: Export Data from listbox to Excel

  #8  
May 11th, 2008
My advice is stick with it and study. Nobody ever became a code guru overnight :-) Practice practice practice. Oh and some good tutorials will help too.

Here is one I found that looks promising.

If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
Reply With Quote  
Join Date: Nov 2007
Location: Jogja
Posts: 2,330
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 9
Solved Threads: 204
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

Re: Export Data from listbox to Excel

  #9  
May 12th, 2008
i learn from many resource friend.
from books (i have many books), internet (google), Asking from anybody and trying it by myself. like my signature Never tried Never Know
Actually this forum is a great place to learn, many people with different experience will give u a many example in different type.
Microsoft supplied MSDN, looks for function that u dont know there.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Re: Export Data from listbox to Excel

  #10  
May 12th, 2008
U gave me tips thx,but u do not reply to me answer frnd.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb VB.NET Marketplace
Thread Tools Display Modes

Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 10:47 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC