Solved

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

Posted on 2010-08-26
9
1,790 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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 500 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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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