将DataGridView数据导出到C#中的Excel文件 [英] Exporting DataGridView data to Excel file in C#
问题描述
我需要将数据从DataGridView(在我的WinForms应用程序中)导出到excel文件。我在这个主题上搜索了一些教程,但是我很难得到任何可用的解决方案。
我从本教程。但是当我尝试将datagridview导出到excel文件时,我收到了未处理的COMException:
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
我也尝试过本教程,但结果相同。
另一篇文章我已找到并阅读了这一个无法获取代码工作,可能是因为在 COM选项卡
中找不到 Microsoft Excel 12.0对象库
的添加参考
对话框。
我使用的是Visual Studio 2010 Ultimate。
如果没有安装这些库,可以从Microsoft下载:
,请看这里:
2007 Microsoft Office系统更新:可再分发主要互操作程序
Microsoft Office 2010:主要互操作程序集可再发行
安装完毕正确的一个,你应该可以在教程的添加引用一节中找到该库
I need to export data from DataGridView (in my WinForms application) to excel file. I googled some tutorials on the subject, but I'm having hard time getting any of the available solutions to work.
I started with this tutorial. But when I try to export datagridview to excel file i get Unhandled COMException in:
Microsoft.Office.Interop.Excel.ApplicationClass ExcelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
I've also tried this tutorial, but with the same result.
Another of the articles I've found and read was this one. Couldn't get code to work, probably because I can't find Microsoft Excel 12.0 object library
in the COM tab
of Add Reference
dialog.
I'm using Visual Studio 2010 Ultimate.
If those libraries are not installed, you can download them from Microsoft:
For Specific office versions, see here:
Office 2003 Update: Redistributable Primary Interop Assemblies
2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies
Microsoft Office 2010: Primary Interop Assemblies Redistributable
Once you install the correct one, you should be able to find the library in the 'Add reference' section of the tutorials
这篇关于将DataGridView数据导出到C#中的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!