日期:2014-05-17 浏览次数:20460 次
HttpContext.Current.Response.AppendHeader( "Content-Disposition ", "attachment;filename=Excel.xls "); HttpContext.Current.Response.Charset = "UTF-8 "; HttpContext.Current.Response.ContentEncoding =System.Text.Encoding.Default; HttpContext.Current.Response.ContentType = "application/ms-excel ";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword ctl.Page.EnableViewState =false; System.IO.StringWriter tw = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End();
------解决方案--------------------
这个跟自己电脑上的excel组件有关系。你可以尝试直接将数据到处到excel
------解决方案--------------------
导出失败?有报什么错没???
加这个试试?
public override void VerifyRenderingInServerForm(Control control)
{
}
------解决方案--------------------
有报错么???
加这个试试??
public override void VerifyRenderingInServerForm(Control control)
{
}
------解决方案--------------------
response.write会冲掉以前的东西。不弹出是正常的
------解决方案--------------------
string name = "Rpt" + DateTime.Now.ToString("yyyyMMdd") + ".xls";
Response.Clear();
Response.Buffer = false;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + name);
Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
Response.ContentType = "application/ms-excel";
Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=UTF-\">");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
这样呢???
------解决方案--------------------
导出按钮是不是在UpdatePanel中?