如何将多个网格视图作为excel代码添加到导出的不同工作表中? [英] How do I add multiple gridviews to different workheets to my export as excel code?

查看:61
本文介绍了如何将多个网格视图作为excel代码添加到导出的不同工作表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨成员,



如何在1 ms-excel文件中将2个网格视图(GridView1& GridView2)导出为2个单独的工作表?目前,我只能将1个网格视图导出到Excel工作表,其中文件名与工作表名称相同。但我想将2个网格视图分成2个单独的工作表,我希望自己定义/设置工作表名称。谢谢。



我的主要问题是:



1.如何在我的网格中插入更多网格视图要添加到单独的工作表中的代码(例如Gridview1到工作表1和Gridview2到工作表2)?



2.如何在我的代码中设置每个工作表名称?



3.如何通过在代码中声明文件路径自动将excel下载到文件路径中?





目前,我只能通过点击按钮将1个gridview导出到excel文件中。

Hi members,

How do I export 2 grid views (GridView1 & GridView2) into 2 separated sheets in 1 ms-excel file? Currently, I'm able to export only 1 grid view to an excel sheet which the filename is the same as the sheet name. But I would like to 2 grid views into 2 separated sheets which I would like sheet name to be define/set by myself. thanks.

My main question is:

1.How can I insert more grid views in my code to be add into separate worksheets (e.g Gridview1 into worksheet1 and Gridview2 into worksheet2)?

2.How can I set each of the worksheet names in my codes?

3.How can I download the excel into the file path automatically by stating a file path in my code?


Currently, Im only able to export 1 gridview into an excel file with the click on a button.

   public void ExportGridToExcel()
{
    Response.Clear();
    Response.Buffer = true;
    Response.ClearContent();
    Response.ClearHeaders();
    Response.Charset = "";
    string FileName ="Export"+DateTime.Now+".xls";
    StringWriter strwritter = new StringWriter();
    HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition","attachment;filename=" + FileName);
    GridView1.GridLines = GridLines.Both;
    GridView1.HeaderStyle.Font.Bold = true;
    GridView1.RenderControl(htmltextwrtter);
    Response.Write(strwritter.ToString());
    Response.End();
}
 
    public override void VerifyRenderingInServerForm(Control control)
    {
        return;
    }

推荐答案

您将在 CP知识库 [ ^ ]。大量的例子正在等待发现。
The answer to all your questions you'll find on CP Knowledge Base[^]. Tons of examples is waiting for discover.


这篇关于如何将多个网格视图作为excel代码添加到导出的不同工作表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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