出口GridView的创先争优为3个工作表 [英] exporting gridviews to excel into 3 worksheets

查看:188
本文介绍了出口GridView的创先争优为3个工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的网站,我有一个按钮,调用一个方法,然后生成报告出类拔萃。在code工作。问题是,code显示(有3)同一选项卡上的所有GridView的。我想补充什么code本,这样,当我点击按钮,它会下载该文件,但必须显示在其单独的选项卡每个gridview的。该标签名称将是前1,前2名,和前3名。所以要澄清,现在所有的GridView的的显示在顶部1选项卡上,我需要做2个选项卡(顶部2和顶部3),并把gridview2顶部2标签,上面3选项卡上gridview3。只有1数据集。可我使用循环它什么code,以便它显示每个表分成不同的工作表?

 公共部分类_Default:System.Web.UI.Page
{
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    数据集的数据集=新的DataSet();    康涅狄格州的SqlConnection =新的SqlConnection(ConfigurationManager.ConnectionStrings [ISALog1ConnectionString]的ToString());    CMD的SqlCommand =新的SqlCommand(EXEC ProxyReport,康恩);
    cmd.CommandTimeout = 200;    SqlDataAdapter的广告=新SqlDataAdapter的(CMD);
    ad.Fill(数据集);    GridView1.DataSource = dataSet.Tables [0];
    GridView1.DataBind();
    GridView2.DataSource = dataSet.Tables [1];
    GridView2.DataBind();
    GridView3.DataSource = dataSet.Tables [2];
    GridView3.DataBind();}
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
    字符串附件=附件;文件名=顶部1.xls;
    Response.ClearContent();
    Response.AddHeader(内容处置,附件);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType =应用程序/ MS-Excel的;
    StringWriter的SW =新的StringWriter();
    HtmlTextWriter的HTW =新的HtmlTextWriter(SW);
    GridView1.RenderControl(HTW);
    GridView2.RenderControl(HTW);
    GridView3.RenderControl(HTW);
    的Response.Write(sw.ToString());
    到Response.End();
}
公共覆盖无效VerifyRenderingInServerForm(控制控制)
{}
}


解决方案

看起来像的导出GridView控件到多个Excel工作表。看来你将寻找到互操作性展示虽然。

祝你好运。

From my website, I have a button which calls a method and then generates reports to excel. the code works. The problem is that the code displays all gridviews (there are 3) on the same tab. What code may I add to this so that when i click on the button, it will download the document but have each gridview displayed on their separate tabs. The tab names will be top 1, top 2, and top 3. So to clarify, right now all of the gridviews are displayed on the top 1 tab, I need to make 2 more tabs (top 2 and top 3) and put gridview2 on top 2 tab, and gridview3 on the top 3 tab. There is only 1 data set. What code could i use to loop it so that it displays each table into different worksheets?

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    DataSet dataSet = new DataSet();

    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ISALog1ConnectionString"].ToString());

    SqlCommand cmd = new SqlCommand("exec ProxyReport", conn);
    cmd.CommandTimeout = 200;

    SqlDataAdapter ad = new SqlDataAdapter(cmd);
    ad.Fill(dataSet);

    GridView1.DataSource = dataSet.Tables[0];
    GridView1.DataBind();
    GridView2.DataSource = dataSet.Tables[1];
    GridView2.DataBind();
    GridView3.DataSource = dataSet.Tables[2];
    GridView3.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
    string attachment = "attachment; filename=Top 1.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/ms-excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    GridView1.RenderControl(htw);
    GridView2.RenderControl(htw);
    GridView3.RenderControl(htw);
    Response.Write(sw.ToString());
    Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{

}


}

解决方案

Looks like a duplicate of Export GridView to multiple Excel sheet. It seems that you will be looking into interops though.

Good luck.

这篇关于出口GridView的创先争优为3个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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