•
•
•
•
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 397,577 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 3,384 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: 1479 | Replies: 5
![]() |
•
•
Join Date: Nov 2007
Location: High Point, NC
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 4
The first thing that you'll need to do is add a reference to the Microsoft Excel Object Library. In your code you will need to create an Excel application object and excel workbooks. Then you should be able to access the file to edit the cells. It may look something like this;
There is information about manipulating the data at this link, http://support.microsoft.com/default...b;EN-US;302094
'declare an instance of an excel application
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
'make a book
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
'set it to the excel doc
oBook = oExcel.Workbooks.Open("path to your file")
'get the sheet
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet = oBook.Worksheets("Sheetname")
'here you would put any other code to edit the sheetThere is information about manipulating the data at this link, http://support.microsoft.com/default...b;EN-US;302094
•
•
Join Date: Nov 2007
Location: High Point, NC
Posts: 37
Reputation:
Rep Power: 1
Solved Threads: 4
If you are wanting to just read what is on the sheet like it is a database column you would use an OleDb connection object like this;
Then use as any other OleDb connection. To access individual cells you need to create Excel objects like the post above and then loop through each row and cell, check the link in that post for examples.
Dim strSql As String = "select * from [" & SheetName & "$]"
Dim conConn As New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=" & c:\PathToFile & "; " & _
"Extended Properties=Excel 8.0;")
Dim cmd As New OleDb.OleDbCommand(strSql, conConn)
Dim dr As OleDb.OleDbDataReaderThen use as any other OleDb connection. To access individual cells you need to create Excel objects like the post above and then loop through each row and cell, check the link in that post for examples.
Last edited by emurf : Dec 31st, 2007 at 11:49 am.
A word of warning I found out later if using oledb - the spreadsheet must be perfect
In other words:
Every column must either number numeric or non-numeric, if there is a mismatch it doesn't work.
In other words:
Every column must either number numeric or non-numeric, if there is a mismatch it doesn't work.
Last edited by iamthwee : Jan 1st, 2008 at 3:03 pm.
Member of: F-ugly code club
Join today don't delay!
Join today don't delay!
•
•
Join Date: Feb 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Hi All,
I've some excel programs. I want to attach those programs to my vb.net application. Is it possible? If yes then How? If its possible then can the excel file be editable?
plz check this
http://vb.net-informations.com/excel..._tutorials.htm
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
- Get data out of excel file stored as an image (MS SQL)
- Virus slowing down desktop till it can't be used (Viruses, Spyware and other Nasties)
- My hompage keeps going to saftyhomepage.net (Viruses, Spyware and other Nasties)
- Windows program closing automatically on opening- HIJACK LOG posted (Viruses, Spyware and other Nasties)
- Desktop won't load (Viruses, Spyware and other Nasties)
- DNS error with IE -- Posted HIJACK Log (Viruses, Spyware and other Nasties)
- Need help with stubborn spyware problem (Viruses, Spyware and other Nasties)
- System 32 Coming Up at Startup (Viruses, Spyware and other Nasties)
Other Threads in the VB.NET Forum
- Previous Thread: VB.net connects
- Next Thread: OBD II



Linear Mode