将Excel单元格读取到C#程序中 [英] Reading Excel cells into a C# program

查看:68
本文介绍了将Excel单元格读取到C#程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网上寻找一种做到这一点的方法,每个人都解释得如此复杂,我听不懂...所以也许有人可以更好地解释

有没有办法使Excel表格中的C#程序(控制台或表单)读取?
就像使用Textreader和Streamreader从文本文件读取.. :)
我是编程的新手,并且对学习更多内容非常感兴趣.如果有人能用非常基本的术语来解释该怎么做,我将不胜感激!

I''ve been looking around the web for a way to do this and everyone explains it so complicatedly and I can''t understand it... so maybe someone here can explain better

Is there a way to make a C# program (Console or form) read from an Excel sheet?
Much like reading from a text file with Textreader and Streamreader.. :)
I''m a newbie to programming and very interested in learning more. If anyone could explain in very basic terms how to do this I''d really appreciate it!!

推荐答案

嗯,一个excel文件与任何纯文本文件都不一样,所以诸如StreamReader或TextReader之类的方法将无济于事,您必须以对c#可读的方式导入文件,即在应用程序中实例化OleDB或COM对象以读取文件,最常见的做法是使用Excel API就是一个例子.

http://csharp.net-informations.com/excel/csharp-read-excel.htm [^ ]
Humm an excel file is not like any plain text file so things like StreamReader or TextReader will not help, you must import the file in a way that is "readable" for c# , that is instantiating a OleDB or a COM Object in your application to read the file, the most common thing to do is use the Excel API here is an example.

http://csharp.net-informations.com/excel/csharp-read-excel.htm[^]


有几种解决方法:

1)]如果您要使用Office 2007及更高版本

2)
Microsoft Jet [ ^ ]来阅读Office 2003及更低版本(尽管我还没有尝试使用新版本)

3)互操作 [
There are several ways to go about this:

1) OpenXml[^] if you''re dealing with Office 2007 and up

2) Microsoft Jet[^] to read Office 2003 and below (though I haven''t tried it with newer versions)

3) Interop[^] - Which is probably the least preferable as it is the slowest and has the most dependencies.


这篇关于将Excel单元格读取到C#程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆