DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   how to link an excel program in vb.net? (http://www.daniweb.com/forums/thread99345.html)

mpatram Dec 3rd, 2007 12:36 am
how to link an excel program in vb.net?
 
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?

emurf Dec 3rd, 2007 11:42 am
Re: how to link an excel program in vb.net?
 
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;
'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 sheet

There is information about manipulating the data at this link, http://support.microsoft.com/default...b;EN-US;302094

隐姓埋名 Dec 27th, 2007 1:07 pm
Re: how to link an excel program in vb.net?
 
I wonder how to process the data in the excel cells with the vb.net codes. thnx

emurf Dec 31st, 2007 11:48 am
Re: how to link an excel program in vb.net?
 
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;
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.OleDbDataReader

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.

iamthwee Jan 1st, 2008 3:02 pm
Re: how to link an excel program in vb.net?
 
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.

rps_x Mar 23rd, 2008 2:22 am
Re: how to link an excel program in vb.net?
 
Quote:

Originally Posted by mpatram (Post 482885)
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


All times are GMT -4. The time now is 8:27 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC