******动态生成控件导出Excel问题。200分******
导出Excel时出现如下异常
******动态生成控件导出Excel问题。200分******
如下:
由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值
没有将Table中内容全部导出来,只导出一部分,而且这部分还是乱码;
我刚才试了以下,导出正常的好像也会出现这个错误,但是可以将内容导出
我是动态生成的DataTable,然后将DataTAble的内容导出到Excel
导出Excel的代码如下:
/// <summary>
/// 导出到Excel
/// </summary>
/// <param name= "sender "> </param>
/// <param name= "e "> </param>
protected void Btn_Excel_Click(object sender, EventArgs e)
{
try
{
//此处是从新画出表格
Table_Report.Rows.Clear();
ReportTile(Table_Report);
ReportContent(Table_Report);
//以下是导出Excel部分,该部分应该没问题,我其它导出也是用这个代码,没问题
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= " + System.Web.HttpUtility.UrlEncode( "导出 " + System.DateTime.Now.Date.ToString( "yyyyMMddhhmmss ")) + ".xls ");
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ");//设置输出流为简体中文
Response.ContentType = "application/ms-excel ";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "zh-CN ", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.Table_Report.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString