Search code examples
c#databaseoledbexcel-2007excel-interop

Which One is Best OLEDB Or Excel Object Or Database


I need to work with Excel 2007 File for reading the data. for that which one is the best way to do that:

  1. Using OLEDB Provider
  2. Excel Interop Object
  3. Dump the Excel data to Database and Using Procedure

kindly guide me to choose.


Solution

  • Here are my opinions:

    1. Using OLEDB Provider

    will only suit your needs if you have simple, uniform structured tables. It won't help you much, for example, if you have to extract any cell formatting information. The Jet engine's buggy "row type guessing" algorithm may make this approach almost unusable. But if the data type can be uniquely identified from the first few rows of each table, this approach may be enough. Pro: it is fast, and it works even on machines where MS Excel is not installed.

    2. Excel Interop Object

    may be very slow, especially compared to option 1, and you need MS Excel to be installed. But you get complete access to Excel's object model, you can extract almost every information (for example: formatting information, colors, frames etc) that is stored in your Excel file and your sheets can be as complex structured as you want.

    3. Dump the Excel data to Database and Using Procedure

    depends on what kind of database dump you have in mind, and if you have a database system at hand. If you are thinking of MS access, this will internally use the Jet engine again, with the same pros and cons as approach 1 above.

    Other options:

    4. write an Excel VBA macro to read the data you need and write it to a text file. Read the text file from a C# program. Pro: much faster than approach 2, with the same flexibility in accessing meta information. Con: you have to split your program in a VBA part and a C# part. And you need MS Excel on your machine.

    5. Use a third party library / component for this task. There are plenty of libraries for the job, free and commercial ones. Just ask Google, or search here on SO. Lots of those libs don't require MS Excel on the machine, and they are typically the best option if you are going to extract the data as part of a server process.