使用 C# 将对象导出到 Excel

发布于 2024-09-04 16:21:43 字数 72 浏览 3 评论 0原文

在 C# (.net Framework 3.5) 中将对象导出到 Excel 文件的最佳方法是什么?

提前致谢!

What is the best way to export objet to excel file in C# (.net framework 3.5)?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤寂小茶 2024-09-11 16:21:43

如果是表格数据,您可以生成 HTML 表格并让 Excel 直观地打开它。否则我会推荐 COM Interop。

If it's tabular data, you could generate HTML tables and let Excel open it up intuitively. Otherwise I'd recommend COM Interop.

花期渐远 2024-09-11 16:21:43

我使用 EPPlus 生成 xlsx 文件(基本上是报告 - SQL Reporting Services 2008 R2 仍然不支持它本身就是旧的 xls)。

我听说过有关 NPOI 的好消息,它是 Apache POI 项目

如果您想“本地”执行此操作并与 Excel 的真实实例进行互操作,您可以使用 Excel Primary 中的类互操作程序集 - 查看 microsoft.office.interop。 excel 命名空间

很大程度上取决于您已有的对象类型以及您希望的预期输出是什么 - 如果您可以指定更多内容,我们可以给出更具体的答案。

I've used EPPlus to generate xlsx files (basically reports - SQL Reporting Services 2008 R2 still doesn't support it natively, just the older xls).

I've heard good things about NPOI, which is a .NET port of the Apache POI project

If you want to do it 'natively' and interop with a real instance of Excel, you can use the classes in Excel's Primary Interop Assembly - look in the microsoft.office.interop.excel namespace

A lot depends on what kind of objects you have already and what you want your intended output to be - if you can specify more of that, we can give a more specific answer.

夜夜流光相皎洁 2024-09-11 16:21:43

过去,我使用剪贴板将对象保存为多种格式,然后可以将其粘贴到包括 Excel 或 Word 在内的不同应用程序中,试图在网上找到一个示例,我偶然发现了这一点

: microsoft.com/kb/306023" rel="nofollow noreferrer">http://support.microsoft.com/kb/306023

看起来不错!

In the past I've used the clipboard to save objects to multiple formats that can then be pasted into different applications including Excel or Word, tyring to find an example online I stumble across this:

http://support.microsoft.com/kb/306023

Looks Good!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文