zoukankan      html  css  js  c++  java
  • 导出Excel IT

    直接代码:

            public static void ExportExcel(GridView gv, HttpContext context)
            {
                gv.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(2552550); //rgb(243, 243, 243)
                for (int i = 0; i < gv.Rows.Count; i++)
                {
                    for (int j = 0; j < gv.Rows[i].Cells.Count; j++)
                    {
                        gv.Rows[i].Cells[j].Attributes.Add("style""vnd.ms-excel.numberformat:@");
                    }
                }
                HttpResponse resp = context.Response;
                resp.Charset = "GB2312";
                resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                string fileName = "ExportData.xls";
                if (string.IsNullOrEmpty(gv.ToolTip) == false) fileName = gv.ToolTip+".xls";
                resp.AppendHeader("Content-Disposition""attachment;filename=" +
                    HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8).ToString());
                resp.ContentType = "application/ms-excel";
                StringWriter tw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(tw);
                gv.RenderControl(hw); //输出结构
                string content = "<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">";
                content += tw.ToString();
                content += "</body></html>";
                resp.Output.Write(content);
                resp.Flush();
                resp.End();
            } 
  • 相关阅读:
    rest framework 认证 权限 频率
    rest framework 视图,路由
    rest framework 序列化
    10.3 Vue 路由系统
    10.4 Vue 父子传值
    10.2 Vue 环境安装
    10.1 ES6 的新增特性以及简单语法
    Django 跨域请求处理
    20190827 On Java8 第十四章 流式编程
    20190825 On Java8 第十三章 函数式编程
  • 原文地址:https://www.cnblogs.com/machaofast/p/2658593.html
Copyright © 2011-2022 走看看