导出数据表的内容以显示 [英] export contents of a datatable to exel

查看:81
本文介绍了导出数据表的内容以显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,我已经为那个gridview使用了数据表.我想将所有数据从datatable导出到exel.不是来自gridview. 您需要添加内容类型,标题

 DataGrid dg =  DataGrid();
        dg.Dispose();
        dg.DataSource = dt; // 您的数据表
        dg.DataBind();
        dg.HeaderStyle.Font.Bold =  true ;
                StringWriter sw =  StringWriter();
        HtmlTextWriter hw =  HtmlTextWriter(sw);
        dg.RenderControl(hw);
        Response.Write(sw.ToString()); 


尝试
MSDN- [将数据表从C#导出到Excel] [ ^ ]
对Excel的数据表 [ http://social.msdn.microsoft.com/论坛/en-GB/csharpgeneral/thread/5486f0dd-c168-4cea-bb99-03c92254c8a1 [ 解决方案

See Below Code (Its not a whole code,but gives u idea),
u need to add content-type,header

DataGrid dg = new DataGrid();
        dg.Dispose();
        dg.DataSource =dt; //Your Datatable
        dg.DataBind();
        dg.HeaderStyle.Font.Bold = true;
                StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        dg.RenderControl(hw);
        Response.Write(sw.ToString());


Try
MSDN-[Export dataTable to Excel from C#][^]
Datatable to Excel[^]
having same question with some perfect solution specially take a look of Sandeep Aparajit answer he tries to make a function which enable you to export datatable to Excel.


also see this link and try to understand code... it will more help you

http://social.msdn.microsoft.com/Forums/en-GB/csharpgeneral/thread/5486f0dd-c168-4cea-bb99-03c92254c8a1[^]


这篇关于导出数据表的内容以显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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