473,797 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To read an excel file with Excel Class in vb.net

38 New Member
I have added a reference Microsoft Excel 5.0 Object Library in my project.
the code is as follows:
Dim myExcel As Excel.Applicati on ' Interface to Excel
Dim myWorkBookColle ction As Excel.Workbooks ' Workbook-collection
Dim myWorkBook As Excel.Workbook ' Single Workbook (spreadsheet-collection)
Dim myWorkSheet As Excel.Worksheet ' Single spreadsheet

Dim fdlg As OpenFileDialog = New OpenFileDialog( )
fdlg.Title = "VB.NET Corner Open File Dialog"
'fdlg.InitialDi rectory = "c:\"
fdlg.Filter = "Excel Files (*.Xls)|*.Xls"
fdlg.FilterInde x = 2
fdlg.RestoreDir ectory = True
If fdlg.ShowDialog () = System.Windows. Forms.DialogRes ult.OK Then
txtFile.Text = fdlg.FileName
End If

myExcel = GetObject(, "Excel.Applicat ion")
If myExcel Is Nothing Then
MessageBox.Show ("Could not load Excel.exe")
Exit Sub
End If
' initialise access to Excel's workbook collection
myExcel.Visible = True
myWorkBookColle ction = myExcel.Workboo ks
'open spreadsheet from disk

myWorkBook = myWorkBookColle ction.Open(txtF ile.Text, , False)
'get 1st sheet from workbook
myWorkSheet = myWorkBook.Shee ts.Item(1)
'display the spreadsheet
'myExcel.Visibl e = True 'Read Cell A2
Dim myCell2 As Object = myWorkSheet.Ran ge("A2", System.Reflecti on.Missing.Valu e)
Me.Text = myCell2.Value 'save and get out
myWorkBook.Save ()
myExcel.Quit()

now its giving error at this line
" myWorkBook = myWorkBookColle ction.Open(txtF ile.Text, , False)"

it gives Member Not Found. whereas .open is there in the list.
plz find the solution.
Jan 22 '08 #1
0 1432

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6661
by: see_mun_lee | last post by:
I use asp to develop a web page to read an excel file containing Chinese Character then display it in the web page. Unfortunately, I cant display it!!! it will display (?????????). <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8"> ' create and open the connection to the Excel file Set conn = Server.CreateObject("ADODB.Connection") conn.Open "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" &...
1
4631
by: Esmail Bonakarian | last post by:
Greetings all, What is the best way to access specific records in an Excel file? I have an Excel file, I want to randomly and repeatedly (maybe around up to 50 times) draw some rows of data from this Excel file and store them in a struct/class for further processing. (mostly just display the info in graphical format) This is not some sort of database application, but rather I am
1
3663
by: J Daniel Melton | last post by:
Hello, I am using late binding in a managed VC++ .NET 2003 application. I used KB 302902 (for C#) as a starting point and converted it to managed C++. I built a managed class that is intantiated by a form. The class can instantiate Excel, open a new workbook, add a new worksheet, get a range, and put some data in it. So, I have basically just duplicated what KB 302902 does, except I am working out of a managed C++ class. The problem...
12
6025
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
2
3097
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10209
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7560
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3750
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.