如何从datagrid导出到excel [英] how to export from datagrid to excel

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

问题描述

大家好,



我有一个DataGridTemplateColumns数据网格。我想将datagrid导出到excel文件。



我有一个方法适用于导出,除了它不适用于TemplateColumns。



我在这里附上我的方法。





Hi all,

I have a datagrid with DataGridTemplateColumns. I want to export the datagrid to excel file.

I got a method works great for the exporting except it doesn't work for the TemplateColumns.

I attached my method here.


private void ExportToExcel()
{
    gridTestScript.SelectAllCells();
    gridTestScript.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
    ApplicationCommands.Copy.Execute(null, gridTestScript);
    String resultat = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
    String result = (string)Clipboard.GetData(DataFormats.Text);
    gridTestScript.UnselectAllCells();
    System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Intel\test.xls");
    file.WriteLine(result.Replace(',', ' '));
    file.Close();

    MessageBox.Show(" Exporting DataGrid data to Excel file created");
}







任何帮助都会非常感激



谢谢




Any help would be really appreciated

Thanks

推荐答案

请参阅此内容。



http://www.aspsnippets.com/Articles/Export-GridView-with -TemplateField-Column-to-Excel-in-ASPNet.aspx [ ^ ]



HTTP://www.aspsnippets。 com / Articles / Export-ASPNet-GridView-with-TemplateField-Column-to-Excel-after-removal-controls-like-HyperLink-TextBox-and-Button.aspx [ ^ ]
Refer this.

http://www.aspsnippets.com/Articles/Export-GridView-with-TemplateField-Column-to-Excel-in-ASPNet.aspx[^]

http://www.aspsnippets.com/Articles/Export-ASPNet-GridView-with-TemplateField-Column-to-Excel-after-removing-controls-like-HyperLink-TextBox-and-Button.aspx[^]


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

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