interface excel trough VB.NET

MKP

New member
Joined
Jan 25, 2003
Messages
2
How to read cell(1,1) and cell(1,2) from an excel workbook (c:/add.xls); worksheet (sheet1) and add the two numbers and display output in excel sheet (sheet 2 of c:/add.xls) cell(1,1)?
 
Try Using Microsoft EXCEL Object in your application. on MSDN Library site there is a complete list of EXCEL Object and their properties.
 
Use the following line to open an Excel application:
Dim Xl As New Excel.Application()

Use the following line to open an Excel file (abc.xls)
Dim Xlb As Excel.Workbook = Xl.Workbooks.Open(abc.xls)

Use the following line to connect to Sheet1:
Dim Xls As Excel.Worksheet = CType(Xlb.Worksheets(1), Excel.Worksheet)

Use the following line to connect to Sheet2:
Dim Xlsa As Excel.Worksheet = CType(Xlb.Worksheets(2), Excel.Worksheet)


Use the following line to copy from Sheet1: A1 to Sheet2: A2
xlsa.cells(1,1).value=xls.cells(1,1).value

Hope this helps. Dont forget to close files and application. Good luck.
 
Gizmo- Can u show the proper way to close the file and application in your example?

Thxs!
 
For the example I gave earlier, you can use the following to close the file, quit application, and free objects.

Xlb.Close(False)
Xl.Application.Quit()
Xl = Nothing
Xlb = Nothing
Xls = Nothing
Xlsa=Nothing

Good Luck.
 
Back
Top