[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-08-26
9
Medium Priority
?
1,793 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 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