将数据从数据集导出到 Excel
我正在尝试将数据从数据集导出到 Excel 并将其直接保存到给定路径,而不给我打开、保存或取消的选项。
I am trying to export data from dataset to excel and save it directly to a given path without giving me the option to open,save or cancel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 ExcelLibrary 这是一个单行...
另请参阅从 C# 创建 Excel(.XLS 和 .XLSX)文件
Using ExcelLibrary this is a one liner ...
See also Create Excel (.XLS and .XLSX) file from C#
此C# Excel 库也可用于导出数据集。有关如何导出的更多详细信息,请参阅此处。
This C# Excel library can also be used to export the dataset. More details about how to export can be found here.
这不是最好的解决方案,但这就是我所做的,它打开一个新的 Excel 文档,然后复制数据集中的内容,您所需要做的就是整理列并保存它。
顺便说一句,这是我回答问题的第一篇文章,希望它有所帮助
It's not the greatest solution but here is what I did, it opens a new excel document then copies what is in the dataset, all you need to do is sort out the columns and save it.
Btw totes my first post to answer a question, hope it helps
检查此 DataSetToExcel
和 c# (WinForms-App) 将数据集导出到 Excel
在第一个链接中,更改代码如下:
删除最初启动的所有代码并尝试以下操作
Check this DataSetToExcel
and c# (WinForms-App) export DataSet to Excel
In the first link change the code as follows:
Remove the all code that initially starts and try the following
这是另一个 C# 库,它允许您使用 OpenXML 库将数据集导出到 Excel 2007 .xlsx 文件。
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
所有源代码以及演示应用程序均免费提供,您可以在 ASP.Net、WPF 和 WinForms 应用程序中使用它。
将类添加到应用程序后,只需调用一个函数即可将数据导出到 Excel 文件中。
没有比这更容易的了。
祝你好运 !
Here's another C# library, which lets you export from a DataSet to an Excel 2007 .xlsx file, using the OpenXML libraries.
http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
All of the source code is provided, free of charge, along with a demo application, and you can use this in your ASP.Net, WPF and WinForms applications.
Once you've added the class to your application, it just takes one function call to export your data into an Excel file.
It doesn't get much easier than that.
Good luck !
嗨,我找到了一个完美的解决方案 此处
只需将代码中的 'missing.value' 替换为 System.Type.Missing 即可。同时删除
oWB.Close(System.Type.Missing, System.Type.Missing, System.Type.Missing);
和
oXL.Quit();
从代码中。否则你的Excel一打开就会自动关闭。
Hi i found a perfect solution Here
Just replace 'missing.value' with System.Type.Missing in the code. Also remove
oWB.Close(System.Type.Missing, System.Type.Missing, System.Type.Missing);
and
oXL.Quit();
from the code. Otherwise your excel will get closed automatically as soon as it open.