导出到Excel显示空白表 [英] Export to Excel shows an empty sheet
本文介绍了导出到Excel显示空白表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我运行导出到Excel"时,Spreadheet包含数据,但是如果我通过邮件发送,则该数据将为空.有人知道这可能是什么原因吗?
代码是:
When I run my Export to Excel, the Spreadheet contains data but if i send it via mail it becomes empty. Anyone know what may cause this?
the code is :
string attachment = "attachment; filename=att_Data.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
Response.Write(sw.ToString());
Response.End();
推荐答案
//Stopwatch sw1 = Stopwatch.StartNew();//1.85
////#region "Downloading excel file with Certificate Track data "
//System.IO.StringWriter tw = new System.IO.StringWriter();
//System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
//DataGrid dgGrid = new DataGrid();
//dgGrid.DataSource = objDataTable;
//dgGrid.DataBind();
////Get the HTML for the control.
//dgGrid.RenderControl(hw);
//HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
//HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
////this.EnableViewState = false;
//HttpContext.Current.Response.Write(tw.ToString());
//sw1.Stop();
//TimeSpan elapsed = sw1.Elapsed;
//HttpContext.Current.Response.End();
//System.Diagnostics.Process.Start(finalFileNameWithPath);
这篇关于导出到Excel显示空白表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文