Which One is Best OLEDB Or Excel Object Or Database

前端 未结 2 1918
醉梦人生
醉梦人生 2021-02-02 01:19

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
相关标签:
2条回答
  • 2021-02-02 01:56

    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.

    0 讨论(0)
  • 2021-02-02 02:05

    Options 1 and 2 are almost always an exercise in pain, no matter how you ask the question.

    If you can use SSIS to move the data into a database, and if that suits your needs because of other requirements, that's also a good option.

    But the preferred option is usually to use Office Open XML for Excel 2007 and later. That has none of the COM headaches you get with Option 2, and none of the issues you have with guessing row types as you have with Option 1.

    With a more carefully crafted question, you can get a far better answer, though.

    0 讨论(0)
提交回复
热议问题