DateTime date = new DateTime();
date = DateTime.Now;
this.Response.Clear();
this.Response.Buffer= true; 
this.Response.Charset="utf-8";
this.Response.AppendHeader("Content-Disposition","attachment;filename=Manufacturing Workshops list-"+date.Year+"_"+date.Month+"_"+date.Day+".xls"); 
this.Response.ContentEncoding=System.Text.Encoding.UTF8;
this.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
this.EnableViewState = false;

System.Globalization.CultureInfo myCItrad = System.Globalization.CultureInfo.CurrentCulture;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);

this.RenderControl(oHtmlTextWriter);

this.Response.Write(oStringWriter.ToString());
this.Response.End();

解决方案 »

  1.   

    如果用excel的com来做.我知道怎么加..这种不清楚..
      

  2.   

    使用ADO.NET,获取Excel文件的元数据,就可以得到Sheet的名字啦。
    详细看这里:
    http://www.cnblogs.com/Jinglecat/archive/2006/08/26/487167.html
      

  3.   


    啊,是导出呀,我的功能 是导出后Sheet的名字是要自己在程序中怎么弄,不是ado读excel
      

  4.   

    没看见你的程序里有导出Excel文件的地方,是这里吗:
    this.RenderControl(oHtmlTextWriter); 
    this.Response.Write(oStringWriter.ToString()); 这怎么保证输出的是Excel格式的文件?
      

  5.   


    this.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。