• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

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

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
pmac38CDS
Asked:
pmac38CDS
1 Solution
 
quizwedgeCommented:
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
 
mlaiseCommented:
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
 
pmac38CDSAuthor Commented:
Thanks!!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now