HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            Repeater1.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
导出的数据时这样的
怎样才能导出的只有数据,没有多余的代码

解决方案 »

  1.   

    如果是grid本身导的请参考
    http://fineui.com/demo/#/demo/grid/grid_excel_aspnet.aspx
    如果是用NOPI请参考
    http://blog.csdn.net/apollokk/article/details/8025611
      

  2.   

    Refer:
    http://www.cnblogs.com/insus/archive/2013/01/16/2862121.html
      

  3.   

    估计3#的哪个dll能搞定,但是哪个dll肯定不能搞定复杂报表。LZ你的导出少了 <table></table> 标签,这个导出无论样式还是数据准确性,基本上都不如3#的方法。其实你看看微软的官方文档,也能自己封装出一个3#的dll
      

  4.   

      Response.Clear();
                Response.BufferOutput = true;            //设定输出字符集        
                Response.Charset = "utf-8";
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
                //设置输出流HttpMiME类型(导出文件格式)         
                Response.ContentType = FileType;
                //关闭ViewState       
                Page.EnableViewState = false;
                System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
                System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
                HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
                Repeater1.RenderControl(textWriter);
                //把HTML写回游览器            
                Response.Write(stringWriter.ToString());
                Response.End();
                Response.Flush();