开发者

What is the best approach for inserting data into Excel (2007 and 2010) using C#

My current scenario is that I have 20 Excel files that need to be populated by running multiple scripts. Currently this is a manual process. I am about to start a small project that should automate most if not all of the work.

Tools:

I am currently using Excel 2007, but could potentially be working with Excel 2010 in the near future. I am currently planing to use VS 2005 Professionl or C# Express 2010.

My approach is to create templates for the 20 files, so that formatting and data that is not changing is already saved. Through C# I plan to then insert data at appropriate cells within each "Sheet" per file.

I have come across multiple approaches that I read on (here and other site开发者_Python百科s), namely -

  1. Excel Interop
  2. OLE DB
  3. ADO.NET
  4. Open XML

I am trying to find out if someone has done something similar before and which one of the technologies would work best (if possible with some explanation or link for more information).

I am sorry if the question is too subjective and not appropriate. I will understand if someone decides to close it.

Thanks.


I might be missing something, but I would think OLE DB and ADO.Net end up being the same if you are talking C#. Basically, you would use the OLE DB provider for Excel for ADO.Net. I recommend http://www.connectionstrings.com/ for how to setup your provider.

However, if you are going to use templates, it's pretty easy. Just setup your "tables" in your Excel files. Make sure you use named ranges. All that is left is to write some basic SQL like:

INSERT INTO customers(id,name) VALUES (?, ?)

And that is it. I have used it occasionally for data manipulation. I do use it far more often for data reading.

Regards,

Eric.


I think OLE DB is the easyest way to do this.


OLEDB is for me the best way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜