导出EXCEL的怪问题
九章落地 2006-12-28 10:46:45 我有一页面,通过下面的方式把<div></div>之间的数据导出到EXCEL,如果是执行單一页面,没有问题。但我的整个站点是用框架做的,把该页面以框架的方式打开,再导出EXCEL时,有两种情况:如果我选择弹出对话框里的“打开”,我的整个IE窗口都会关掉;如果选择“保存”,IE也会关掉,但EXCEL能下载回本地。
希望得到各位高手的帮助!!!!
源码如下:
//导出函数
private void GenerateByHtmlString(string FileType, string FileName)
{
Response.Charset = "utf-8";
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(FileName));
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
divtest.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
//按钮里调用:
protected void btnOutExcel_Click(object sender, EventArgs e)
{
GenerateByHtmlString("application/ms-excel", "ResApply.xls");
}