?
Solved

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

Posted on 2013-01-02
4
Medium Priority
?
505 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
[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
4 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 38737927
0
 
LVL 14

Accepted Solution

by:
quizwedge earned 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

801 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