将GridView数据提取到excel问题中 [英] Extracting GridView data into excel issue

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

问题描述

我有一大块代码可以从Grid View数据中生成excel。但我面临的问题是代码而不是仅仅将网格视图数据提取到excel中,而是将html UI中存在的整个数据复制到excel文件中,即按钮,dorpdown列表等



我想只将网格视图数据提取到excel文件中。请帮我解决一下这个。我的代码如下:



 protected void btnExcelGenerator_Click(object sender,EventArgs e)
{

Response.Clear();
Response.AddHeader(content-disposition,attachment; filename = FileName.xls);
Response.Charset =;
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);

GridViewRefurb.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();

}





非常感谢帮助,提前谢谢

解决方案

请参阅此 - 将GridView导出到Excel时删除编辑删除按钮 [ ^ ]。



你刚才需要在渲染之前隐藏适当的列...

 GridView1.Columns [ 14 ]。可见=  false ; 
GridView1.Columns [ 15 ]。可见= false ;
GridView1.Columns [ 16 ]。可见= false ;


I have a chunk of code to generate excel from Grid View data. But the issue Im facing with this is the code instead of extracting just the grid view data into the excel is copying entire data present in the html UI into the excel file i.e buttons, dorpdown lists e.t.c.

I want to just extract only Grid View data into the excel file. Please help me with this. My code is as below:

protected void btnExcelGenerator_Click(object sender, EventArgs e)
{

    Response.Clear();
    Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
    Response.Charset = "";
    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);

    GridViewRefurb.RenderControl(htmlWrite);
    Response.Write(stringWrite.ToString());
    Response.Flush();
    HttpContext.Current.ApplicationInstance.CompleteRequest();

}



Help is deeply appreciated, thanks in advance

解决方案

Refer this - Remove Edit Delete Button When Exporting GridView To Excel[^].

You just need to hide the appropriate columns before rendering like...

GridView1.Columns[14].Visible = false;
GridView1.Columns[15].Visible = false;
GridView1.Columns[16].Visible = false;


这篇关于将GridView数据提取到excel问题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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