使用.NET导入Excel数据 [英] Import Excel data with .NET

查看:85
本文介绍了使用.NET导入Excel数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在我开始编码之前,我需要确定没有其他人没有这样做

并且我可以使用它。 />

我需要一个导入实用程序,它将数据从Excel导入数据库或.NET中的一些

对象。 Excel中的数据不在结构化列中,但在工作簿中的任何地方都可以存在
。例如,如果我应该导入一个人

以及工作簿中存在的所有他/她的汽车,我希望能够创建一个

导入协议并指定第一个名字存在于单元格Sheet1!C4中,

姓氏在Sheet1!F4中,电话在Sheet1!E10中,所有车辆都在列中

Sheet2!B4。得到的数据库表可能看起来像这样。

Agnes | Carlsson | 123456 | Subaru

Agnes | Carlsson | 123456 | Volvo

Agnes | Carlsson | 123456 | Ford


他们的任何开源项目,框架和/或组件我都可以使用或者看看在?


问候

/ Niklas

Hi

Before I start coding I need to be sure that nobody else has not done it yet
and that I can use it.

I need an import utility which import data from Excel to a database or some
object in .NET. The data in Excel is not in structured columns but can exist
everywhere in the workbook. For example if I am supposed to import a person
and all his/her cars which exist in a workbook I want to be able to create an
import protocol and specify that the first name exist in cell Sheet1!C4, the
last name in Sheet1!F4, telephone in Sheet1!E10 and all cars in in column
Sheet2!B4. The resulting table to a database could look something like this

Agnes|Carlsson|123456|Subaru
Agnes|Carlsson|123456|Volvo
Agnes|Carlsson|123456|Ford

Are their any Open Source projects, Frameworks and/or components which I can
use or have a look at?

Regards
/Niklas

推荐答案

Niklas,


真的不需要这样的东西。您可以使用Excel

自动化模型直接访问工作表,然后获取

这些工作表/单元格中的值。


基本上,您应该在项目中设置对Microsoft Office Primary

Interop Assemblies的引用。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv *@spam.guard.caspershouse.com


" Niklas" < Ni **** @ discussion.microsoft.com写信息

新闻:7B ************************ ********** @ microsof t.com ...
Niklas,

There is really no need for such a thing really. You can use the Excel
automation model to access the sheet directly and then get the values in
those sheets/cells.

Basically, you should set a reference to the Microsoft Office Primary
Interop Assemblies in your project.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Niklas" <Ni****@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...




开始之前编码我需要确定没有其他人没有这样做

还有

并且我可以使用它。


我需要一个导入实用程序,它将数据从Excel导入数据库,或者在.NET中导入一些

对象。 Excel中的数据不在结构化列中,但可以在工作簿中的任何地方存在

。例如,如果我应该导入一个

的人

以及我希望能够创建的工作簿中存在的所有他/她的汽车

an

导入协议并指定单元格Sheet1中存在名字!C4,

Sheet1中的

姓氏!F4, Sheet1中的电话!E10和列中的所有车辆

Sheet2!B4。结果表数据库看起来像

这个


Agnes | Carlsson | 123456 | Subaru

Agnes | Carlsson | 123456 |沃尔沃

Agnes | Carlsson | 123456 |福特


他们的任何开源项目,框架和/或组件我都是b / b $ b可以

使用或查看?


问候

/ Niklas
Hi

Before I start coding I need to be sure that nobody else has not done it
yet
and that I can use it.

I need an import utility which import data from Excel to a database or
some
object in .NET. The data in Excel is not in structured columns but can
exist
everywhere in the workbook. For example if I am supposed to import a
person
and all his/her cars which exist in a workbook I want to be able to create
an
import protocol and specify that the first name exist in cell Sheet1!C4,
the
last name in Sheet1!F4, telephone in Sheet1!E10 and all cars in in column
Sheet2!B4. The resulting table to a database could look something like
this

Agnes|Carlsson|123456|Subaru
Agnes|Carlsson|123456|Volvo
Agnes|Carlsson|123456|Ford

Are their any Open Source projects, Frameworks and/or components which I
can
use or have a look at?

Regards
/Niklas



" Niklas" < Ni **** @ discussion.microsoft.com写信息

新闻:7B ************************ ********** @ microsof t.com ...
"Niklas" <Ni****@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...

他们的任何开源项目,框架和/或组件我都是/>
可以

使用或看看?
Are their any Open Source projects, Frameworks and/or components which I
can
use or have a look at?



是的 - 有很多 - 但是,正如Nicholas已经说过的那样,根本不需要你需要的b $ b ... 。

Yes there are - loads of them - but, as Nicholas has already said, not
required at all for what you need...




我在这里有一些使用Excel的例子:

http://www.sqlservercentral.com/columnists/sholliday/


但是,实际上并没有任何框架。 ..因为excel数据可以是一些

随机。


您可以尝试将excel数据放入数据集......并使用它来处理它/>
......在商业逻辑层类型对象中。


" Niklas" < Ni **** @ discussion.microsoft.com写信息

新闻:7B ************************ ********** @ microsof t.com ...

I have some examples of using Excel here:

http://www.sqlservercentral.com/columnists/sholliday/

But there aren''t really any "frameworks" .. because excel data can be some
random.

You can try putting the excel data into a dataset... and work with it from
there... in a business logic layer type object.


"Niklas" <Ni****@discussions.microsoft.comwrote in message
news:7B**********************************@microsof t.com...




开始之前编码我需要确定没有其他人没有这样做
Hi

Before I start coding I need to be sure that nobody else has not done it



还有

yet


我可以使用它。


我需要一个导入实用程序,它将数据从Excel导入数据库或
and that I can use it.

I need an import utility which import data from Excel to a database or



一些
.NET中的

some


对象。 Excel中的数据不在结构化列中,但
object in .NET. The data in Excel is not in structured columns but can



存在

exist


工作簿中的任何位置。例如,如果我应该导入
everywhere in the workbook. For example if I am supposed to import a



person

person


以及他/她所有存在的汽车在工作簿中我希望能够创建
and all his/her cars which exist in a workbook I want to be able to create




an


导入协议并指定第一个名称存在于单元格Sheet1!C4,
import protocol and specify that the first name exist in cell Sheet1!C4,




the


Sheet1中的姓氏!F4,电话在Sheet1!E10和列中的所有车辆

Sheet2!B4。生成的数据库表可能看起来像
last name in Sheet1!F4, telephone in Sheet1!E10 and all cars in in column
Sheet2!B4. The resulting table to a database could look something like



这个

this


>

Agnes | Carlsson | 123456 |斯巴鲁

Agnes | Carlsson | 123456 |沃尔沃

Agnes | Carlsson | 123456 |福特


是他们的任何开源项目,框架和/或组件我
>
Agnes|Carlsson|123456|Subaru
Agnes|Carlsson|123456|Volvo
Agnes|Carlsson|123456|Ford

Are their any Open Source projects, Frameworks and/or components which I



可以

can


使用或看看?


问候

/ Niklas
use or have a look at?

Regards
/Niklas



这篇关于使用.NET导入Excel数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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