Solved

What's the best way to read excel files in VB.Net

Posted on 2013-01-02
4
494 Views
Last Modified: 2013-01-02
What's the best way to read an XLS/XLSX file in VB.Net.  Right now the way I'm going about it is how we've done it in the past by the following.....

    strConn = "Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=""Excel 12.0;HDR=No;""; Data Source=" & xlsFilePath & ";"

    da = New OleDb.OleDbDataAdapter("SELECT * FROM [Page1_1$]", strConn)
    da.TableMappings.Add("Table", "Excel")
    da.Fill(ds)

Then I access a certain row/col by the following......

ds.Tables(0).Rows.Item(j).ItemArray(1)

Is this the best way to be doing this or should I be using the Microsoft.Office.Interop.Excel that I've been reading about?  I messed with it quickly and the first thing I noticed is it actually opened the XLS file in an Excel Window.  Are there reasons for using this versus what I've been using?  The only real issue I've seen with how I've been doing it is if I have a cell that has over 255 characters.  It has issues with that unless it's in the first X amount of rows.  That isn't a big deal.  Other then that we've never really had any issues.  I was just asked if this was the old way of doing it and if the Microsoft.Office.Interop.Excel was what we should be moving towards.

Any thoughts/suggestions/comments would be greatly appreciated.

Thanks.
0
Comment
Question by:pmac38CDS
4 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 38737927
0
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 38737930
From what I've seen, part of the issue of using Microsoft.Office.Interop.Excel is that it requires you to have a license for Excel. I've also read that it's not a recommended solution for web servers (or perhaps it was servers in general).

The benefit of using Microsoft.Office.Interop.Excel is, I believe, you can finely control cells just like you would modify them in Excel. If you're just looking for something to quickly read the data and don't care about the quirk of it reading the first X rows to find out what type it is, I'd stick with that if for no other reason than to save yourself the headache of licensing and overhead of opening excel.
0
 
LVL 5

Expert Comment

by:mlaise
ID: 38737978
I would use the OLE driver since you do not need a copy of Excel installed on the computer running the application.

The Excel object is good when you have to design an advanced spreadsheet from data.  For reading simple data it will do nothing for you but add more overhead and require Office to be installed on the client computers.
0
 
LVL 1

Author Comment

by:pmac38CDS
ID: 38738063
Thanks!!
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# LINQ ForEach() question 6 54
Easy filter aspnet 2 24
Amazon S3 Images with .Net 3 14
Need help converting bitmap to image in VB.Net 8 23
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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