请各位高手帮一下我的.net web页面中有个iframe,iframe加载了一个页面,里面有生成excel的功能,就是点击一个"生成execel"的按钮后,就会弹出让保存excel文件的对话框,可是一点击“保存”或“取消”主窗口就关闭了,请大家帮着看看这是怎么回事,这是代码:
protected void Button2_Click(object sender, EventArgs e)
{
string excelName =DateTime.Now.Year+"年度" + Common.UtilCommon.ConvertToDoubleString(this.DropDownList1.SelectedValue) + "月份人员值班表.xls";
if (this.GridView1.Rows.Count > 0)
EmpExcel(excelName);
} private void EmpExcel(string excelName)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName, Encoding.UTF8));
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
//System.Globalization.CultureInfo cul = new System.Globalization.CultureInfo("ZH-CN",true);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
protected void Button2_Click(object sender, EventArgs e)
{
string excelName =DateTime.Now.Year+"年度" + Common.UtilCommon.ConvertToDoubleString(this.DropDownList1.SelectedValue) + "月份人员值班表.xls";
if (this.GridView1.Rows.Count > 0)
EmpExcel(excelName);
} private void EmpExcel(string excelName)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "gb2312";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(excelName, Encoding.UTF8));
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
//System.Globalization.CultureInfo cul = new System.Globalization.CultureInfo("ZH-CN",true);
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货