导出到Excel在ASP.NET的弹出窗口中不起作用 [英] Export to excel not working in popup window in asp.net

查看:114
本文介绍了导出到Excel在ASP.NET的弹出窗口中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经在asp.net中创建了一个应用程序,在该应用程序中,单击gridview模板字段时调用了javascript,并从该javascript中打开了一个新的弹出窗口(非模式弹出窗口),我在该弹出窗口中单击了按钮,具有将数据导出到excel的功能.一切正常,但是excel不能视为已下载...

请帮助,这是我的代码..


Hello everyone,

I have made an application in asp.net in which on click of gridview template field a javascript is called and from that javascript a new popup window is opened(not modal popup window), i have button in that popup window on click of which i have a function of exporting data to excel..everything works fine but the excel is not viewed as downloaded...

Please help here is my code..


protected void btmExport_Click(object sender, EventArgs e)
    {
        //Response.Redirect("DownloadComplaintsExcel.aspx");
        DataSet ds = (DataSet)ViewState["ComplaintDataSet"];
        ExportDetails(ds.Tables[0]);
    }
 public void ExportDetails(DataTable dt)
    {
        string fileName = "Complaints-" + DateTime.Today.Day.ToString() + "" + DateTime.Today.Month.ToString() + "" + DateTime.Today.Year.ToString();
        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ContentType = "application/vnd.ms-excel";
        response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\".xls");
       
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        DataGrid dg = new DataGrid();
        dg.DataSource = dt;
        dg.DataBind();
        dg.RenderControl(htw);
        response.Write(sw.ToString());
        response.End();
    }



请帮忙..

问候,
Krunal



Please help..

Regards,
Krunal

推荐答案

您好,您可以在下面的文章中找到有用的内容:
9将数据导出到Excel for ASP的解决方案. NET [ ^ ]
Hello,you can find something useful in below article:
9 Solutions to Export Data to Excel for ASP.NET[^]


无法在Popup中工作,所以我在新标签页中打开了页面.并开始工作..
Was not working in Popup so i have opened the page in new tab.. and started working..


这篇关于导出到Excel在ASP.NET的弹出窗口中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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