execl导出已经实现了,使用nopi实现的,现在的问题是导出的数据有一部分介绍,是html的,导出以后显示的是html代码,能不能导出以后查看时显示的是解析以后内容,就是和从浏览器查看一样的效果。

解决方案 »

  1.   

    public static void OutPutExcel(string html,string filename)
            {            HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.Charset = "GB2312";
                //设置了类型为中文防止乱码的出现 
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls"));
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                //设置输出流为简体中文 
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Write(html);
                HttpContext.Current.Response.End();
            }
        封装好的方法,,,直接调用就好,,,
      

  2.   

    public static void OutPutExcel(string html,string filename)
      {  HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.Buffer = true;
      HttpContext.Current.Response.Charset = "GB2312";
      //设置了类型为中文防止乱码的出现  
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls"));
      HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
      //设置输出流为简体中文  
      HttpContext.Current.Response.ContentType = "application/ms-excel";
      HttpContext.Current.Response.Write(html);
      HttpContext.Current.Response.End();
      }
      封装好的方法,,,直接调用就好,,,
      

  3.   


    GemBox.ExcelLite 用这个!
      

  4.   

    同志们,好像你们说的没有我要的,我要的是怎么设置导出时execl列显示的格式,可以显示html代码格式的单元格格式
    另外不要用导出html代码,另存为xls的方法的,我现在已经导出了标准格式的execl文件,主要是显示html代码问题,比如商品的介绍,存储的是html代码,导出了显示的还是代码,要求显示的是和浏览器一样的效果
      

  5.   

    #region 导出为Excel
        public override void VerifyRenderingInServerForm(Control control)
        {
            // Confirms that an HtmlForm control is rendered for
        }    private void ToExcel(Control ctl, string FileName)
        {
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
            ctl.Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            ctl.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
        }    private void toExcelClk()
        {
            gvSysUser.AllowPaging = false;
            gvSysUser.AllowSorting = false;
            gvSysUser.DataBind();
            ToExcel(gvSysUser, "OFS_Data.xls");
            gvSysUser.AllowPaging = true;
            gvSysUser.AllowSorting = true;
            gvSysUser.DataBind();
        }
        #endregion或者/// <summary>
            /// 将Web控件导出
            /// </summary>
            /// <param name="source">控件实例</param>
            /// <param name="type">类型:Excel或Word</param>
            public void ExpertControl(System.Web.UI.Control source, DocumentType type)
            {
                //设置Http的头信息,编码格式
                if (type == DocumentType.Excel)
                {
                    //Excel
                    Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
                    Response.ContentType = "application/ms-excel";
                }
                else if (type == DocumentType.Word)
                {
                    //Word
                    Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
                    Response.ContentType = "application/ms-word";
                }
                Response.Charset = "UTF-8";  
                Response.ContentEncoding = System.Text.Encoding.UTF8;             //关闭控件的视图状态
                source.Page.EnableViewState =false;              //初始化HtmlWriter
                System.IO.StringWriter writer = new System.IO.StringWriter() ;
                System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
                source.RenderControl(htmlWriter);             //输出
                Response.Write(writer.ToString());
                Response.End();
            }        //文档类型
            public enum DocumentType
            {
                Word,
                Excel
            }