简体   繁体   English

使用C#导出到Excel(在Web应用程序中)

[英]Export to Excel using c#(in webapplication)

i have done Export to Excel code from Gridview to Excel Sheet. 我已经完成了从Gridview导出到Excel工作表的Excel代码。 i have got the download Dialog box. 我有下载对话框。 How to Get the Button Value whether the datas are saved/Downloaded or Dialog box is closed by hitting cancel button ..... 如何通过单击取消按钮.....获取数据保存/下载或对话框关闭的按钮值。

i want to identify the button hitted is Save or Cancel in the Download dialog Box. 我想确定在“下载”对话框中单击的按钮是“保存”或“取消”。

code : 代码:

public void Export(GridView GridView1, DataTable dtGuid) { public void Export(GridView GridView1,DataTable dtGuid){

        string attachment = "attachment; filename=ScratchcardDetails.xls";

        Response.ClearContent();

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/ms-excel";


        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.Visible = true;
        GridView1.DataSource = dtGuid;
        GridView1.DataBind();


        // Create a form to contain the grid

        HtmlForm frm = new HtmlForm();
        this.GridView1.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(this.GridView1);
        frm.RenderControl(htw);
        //Response.Write(style);
        Response.Write(sw.ToString());
        Response.End();


}
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
    // Save hit
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM