zoukankan      html  css  js  c++  java
  • Web页中table导出到execl(带模板)

    1.将excel另存为html,将其复制到aspx文件中

    2.输出格式为excel

      InitData();
                    Response.Clear();
                    Response.Buffer = true;
                    Response.Charset = "GB2312";
                    Response.AddHeader("Content-Disposition", "attachment;   filename=" + new AutoNumber().GetNumberByTime()+ ".xls");//这样的话,可以设置文件名为中文,且文件名不会乱码。其实就是将汉字转换成UTF8     
    
                    // 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
                    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                    this.RenderControl(oHtmlTextWriter);//Add the Panel into the output Stream.
                    //this.GridView1.RenderControl(oHtmlTextWriter);//将gridview输出,你也可以类似的写TextBox1.RenderControl...
                    Response.Output.Write(oStringWriter.ToString());//Output the stream.
                    Response.Flush();
                    Response.End();
  • 相关阅读:
    oss blob上传
    app中画一条细线
    antd和原生交互,原生掉前端的方法
    -webkit-touch-callout 图片下载
    ifram嵌入网址 有跨域问题
    ...state
    数组对象的复制
    在vue中使用tinymce组件
    autofs自动挂载服务
    podmen
  • 原文地址:https://www.cnblogs.com/wangzhenghua/p/3910961.html
Copyright © 2011-2022 走看看