?
Solved

How do I open and read an Excel file in Visual Basic 2010?

Posted on 2010-08-26
9
Medium Priority
?
1,792 Views
Last Modified: 2013-11-27
I am trying to convert a VB 6.0 application to VB 2010.  I am having trouble with opening and reading/writing to Excel workbooks.  Can I see an example?

        Dim xlApp As New Microsoft.Office.Interop.Excel.Application
        Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
        Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
(NOW WHAT???)
0
Comment
Question by:motokent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 4

Expert Comment

by:Bordeaux0113
ID: 33530575
"Excel: Demonstrates how to use Visual Basic to start Excel, create a workbook from a template, update cells in a worksheet that then populate graphs in the workbook, and perform other tasks"

This is one of many Visual Basic Samples included at this address (in a downloadable file):
http://code.msdn.microsoft.com/vb2010samples/Release/ProjectReleases.aspx?ReleaseId=4174
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33530579
I strongly recommend not using Automation to process Excel files. Better use something like http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx
or check http://support.microsoft.com/kb/302094 
0
 
LVL 20

Expert Comment

by:woolnoir
ID: 33530581
what do you want to do with the excel document, you cant just ask us 'now what' as with any programming language we need an idea about what your trying to achieve to assist.
0
Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

 
LVL 53

Expert Comment

by:Dhaest
ID: 33530649
You can also read the data into a dataset, like you would do with a sqlserver, oracle, ... database

Example can be found here:
Reading Excel 2003 and 2007 Files Using OLEDB
http://codehill.com/2009/01/reading-excel-2003-and-2007-files-using-oledb/
0
 

Author Comment

by:motokent
ID: 33530681
Let me give some more details. My first task is to:
1.) Open C:\test.xls
2.) Read columns A-D (all populated rows) into an arraylist in VB2010
For example:
ArrayListTest(0) would get row1:columnsA,B,C,D
ArrayListTest(1) would get row2:columnsA,B,C,D
etc.
3.) Close C:\test.xls
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 33530712
If you use my example above, you'll have a datatable, which you can use to loop over the rows. You can easily query the excel to say you only want the first 4 columns.
0
 

Author Comment

by:motokent
ID: 33530737
Dhaest:  I need to use Visual Basic 2010.  Isn't the example in c#?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 33530765
Here is another example, surely written in vb.net (the version of .net has no impact)

Read Data from Excel using OLEDB
http://vb.net-informations.com/excel-2007/vb.net_excel_oledb.htm
0
 

Author Closing Comment

by:motokent
ID: 33531442
Thanks!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question