如何使用C#将数据从对象写入excel文档? [英] How can I write data from object to excel document using C#?

查看:231
本文介绍了如何使用C#将数据从对象写入excel文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

听起来非常愚蠢,但是...



试图找到有用的东西,但到目前为止我发现只有OleDB的东西...



我有一个对象列表。在每个对象中,我有3个字符串字段。



我需要将所有这些字段写入excel文档(在excel ofcourse中创建表格)。

有一种简单的方法吗? (没有数据库和连接字符串)?

Sounds very stupid but...

Tried to find something usefull but so far I found only something about OleDB...

I have a list of object. In each object I have 3 string fields.

I need to write all of them into excel document (create table in excel ofcourse).
Is there an simple way to do it? (Without database and connection string)?

推荐答案

检查以下链接

http://matijabozicevic.com/blog/csharp-net-development/export-data-to-excel-using-csharp [ ^ ]

C#Generic List数据输出到格式化字符串,CSV文件和Excel工作表窗口的扩展 [ ^ ]

http://stackoverflow.com/questions/1831024/help-converting-generi c-listt-to-excel-spreadsheet [ ^ ]

http://stackoverflow.com/questions/1059951/export-ac-sharp-list-of-lists-to-excel [ ^ ]
check below links
http://matijabozicevic.com/blog/csharp-net-development/export-data-to-excel-using-csharp[^]
C# Generic List Extensions for Data Output to Formatted String, CSV File, and Excel Worksheet Window[^]
http://stackoverflow.com/questions/1831024/help-converting-generic-listt-to-excel-spreadsheet[^]
http://stackoverflow.com/questions/1059951/export-a-c-sharp-list-of-lists-to-excel[^]


你无法在没有OLE或互操作代码的情况下编写原始excel文件(xls,xlsx),并且两者都需要excel才能真正在机器上。



文件是一个可怕的二进制格式,如果你想真正有一个原始的写作,他们的规范是在这里



http://msdn.microsoft.com/en-us/library/cc313154%28v=office.14%29。 aspx [ ^ ]



另一种方法是编写一个简单的逗号分隔值文本文件(CSV),excel支持导入。



http://en.wikipedia.org/wiki/Comma-separated_values [ ^ ]



如果你真的需要xlx,xlsx文件,那么可互操作的代码很容易,但它是excel版本特定的。 OLE的设置和使用有点复杂,但它对于不同的版本是通用的。
You can't really write a raw excel file (xls, xlsx) without either OLE or Interoperable code and both require excel to actually be on the machine.

The files are a horrible binary format and if you want to really have a crack at raw writing them the specification is here

http://msdn.microsoft.com/en-us/library/cc313154%28v=office.14%29.aspx[^]

The alternative is to write a simple comma seperated value text file (CSV) which excel supports on it's import.

http://en.wikipedia.org/wiki/Comma-separated_values[^]

If you really need xlx,xlsx files then interoperable code is easy but it is excel version specific. OLE is a little more complicated to setup and use but it is generic to the different versions.


这篇关于如何使用C#将数据从对象写入excel文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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