Solved

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

Posted on 2013-01-02
4
493 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

803 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