如何将数据从WPF工具包datagrid导出到Excel [英] How to export data from WPF toolkit datagrid to Excel

查看:86
本文介绍了如何将数据从WPF工具包datagrid导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将WPF工具包datagrid(具有来自SQL Server数据库的数据)中的数据导出到excel.

但是当我在google中搜索时,在所有站点中都有从asp.net或vb.net导出的方法

这样的方法在WPF中没有成功.

请通过任何示例代码片段帮助我

I want to export data from WPF toolkit datagrid (which has the data from the SQL server database) to excel.

But when I search in the google, in all sites there is the method to export from asp.net or vb.net

Such methods are not get success in the WPF.

Pls help me through any sample code snippets

推荐答案

我发现了与Google的这种交流:

WPF的DataGrid与ASP.net的DataGrid有所不同.使用WPF的DG导出为ex​​cel的一种方法是使用DataGrid.CopyToClipboard命令,该命令以CSV,html和文本格式进行复制.从那里,您可以只创建一个csv文件,也可以使用excel API创建一个excel文件.希望有帮助.



我可能非常需要午餐,但是找不到WPF数据网格的CopyToClipboard命令或类似命令.您是否可以提供一个简短的代码段,因为我抓挠了头,并且明显地遗漏了一些明显的内容.

对不起,我想我想说的是DataGrid的内置复制功能. DataGrid具有ClipboardCopyMode并确实使用命令进行复制,但是自定义它的唯一方法是通过重写受保护的复制方法之一.默认的复制功能确实会创建我上面描述的格式,因此您应该能够将其导出为ex​​cel.




Google很简单.至于代码片段,您可以自己完成,但您只需几行就能开发出代码.
I found this exchange with google:

WPF''s DataGrid is a bit different than ASP.net''s DataGrid. One way you can export to excel with WPF''s DG is to use the DataGrid.CopyToClipboard command which makes a copy in a CSV, html, and text format. From there you can either just create a csv file or use the excel APIs to create an excel file. Hope that helps.



I might be in dire need of lunch but I can''t find a CopyToClipboard command or anything like it for the WPF datagrid. Would it be possible for you to provide a brief code snippet because I''m scratching my head and clearly missing something obvious.

Sorry, I think what I meant to say was the built in copy functionality of DataGrid. DataGrid has a ClipboardCopyMode and does use a command to do a copy but the only way you can customize it is by overriding one of the protected copy methods. The default copy functionality does create the formats that I describe above so you should be able to export that to excel.




Google is easy. As for code snippets, you''re on your own, but you should be able to develop the code for this in just a few lines.


这篇关于如何将数据从WPF工具包datagrid导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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