我是用下面的代码把查询到的数据导成excel的,但是再弹出下载和令存为的对话框时,不管我上按取消,还是按令存为,只要按了一下按扭,网页立刻全部关闭,(但是可以成功的导成excel),不知道什么原因public void EduceExcel(DataTable dt, string FileName, string[] biaotou)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Buffer = true;//设置缓冲输出 
        HttpContext.Current.Response.Charset = "GB2312";//设置输出流的HTTP字符集        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=\"" + System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls\"");
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        HttpContext.Current.Response.ContentType = "application/ms-";
        //_page.EnableViewState = false;//是否保持视图状态        HttpContext.Current.Response.Write(HTML(dt, biaotou));
        HttpContext.Current.Response.End();
    }
    #region 构造HTML
/// <summary>
/// 使用DataSet数据源
/// </summary>
/// <param name="ds"></param>
/// <param name="biaotou"></param>
/// <returns></returns>
    private string HTML(DataTable dt, string[] biaotou)
    {
        System.Text.StringBuilder ss = new System.Text.StringBuilder();
        ss.Append("<table>");
        ss.Append("<tr>");
        ss.Append(" <td>序号</td>");
        foreach (string str in biaotou)
        {
            ss.Append(" <td>&nbsp;" + str + "</td>");
        }
        ss.Append("</tr>");
        int ii = 1;
        foreach (DataRow dr in dt.Rows)
        {
            ss.Append("<tr>");
            ss.Append(" <td>&nbsp;" + (ii++).ToString() + "</td>");
            int I = dr.Table.Columns.Count;
            for (int i = 0; i < I; i++)
            {
                ss.Append(" <td>&nbsp;" + dr[i].ToString() + "</td>");
            }            ss.Append("</tr>");
        }
        ss.Append("</table>");        return ss.ToString();
    }
    #endregion