写数据gridview到excel表...... [英] write data gridview to excel sheet......

查看:51
本文介绍了写数据gridview到excel表......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中有一个gridview,我想写excel表中的所有数据,plz帮助我.........

解决方案

< blockquote> 将Gridview数据导出到ASP.NET中的Excel [ ^ ]

导入和导出数据来自GridView [ ^ ]

CodeProject常见问题系列1:ASP.NET GridView [ ^ ]


http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel -or.html [ ^ ]






像这样使用



 protected void btnExcel_Click(object sender,ImageClickEventArgs e)
{
//导出到excel
响应。明确();
Response.AddHeader(content-disposition,attachment; filename = FileName.xls);
Response.Charset =;

//如果你想要选项打开Excel文件而不保存那么
//注释掉
//下面的行// Response.Cache.SetCacheability(HttpCacheability.NoCache) ;
Response.ContentType =application / vnd.xls;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
// GV是gridview
GV.RenderControl(htmlWrite)的ID;
Response.Write(stringWrite.ToString());
Response.End();
}





谢谢


I have a gridview in asp.net and i want to write that all data in excel sheet,plz help me.........

解决方案

Export Gridview Data to Excel in ASP.NET[^]
Import and Export Data from GridView[^]
CodeProject Frequently Asked Questions Series 1: The ASP.NET GridView[^]


http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel-or.html[^]


Hi,

use like this

protected void btnExcel_Click(object sender, ImageClickEventArgs e)
    {
        //export to excel
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
        Response.Charset = "";

        // If you want the option to open the Excel file without saving then
        // comment out the line below
        // Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
       //GV is the ID of gridview
        GV.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();
    }



Thanks


这篇关于写数据gridview到excel表......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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