Learn how to a build a cloud-first strategyRegister 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,796 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
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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 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