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();
            } 
  • 相关阅读:
    【转】PHP实现系统编程(四)--- 本地套接字(Unix Domain Socket)
    php monolog 的写日志到unix domain socket 测试终于成功
    dhcp 过程
    【转】nginx 和 php-fpm 通信使用unix socket还是TCP,及其配置
    php 获取TZ时间格式
    React.Fragment 包裹标签
    git 关联远程分支
    select * from (select user())a 为什么是查询user()的意思?
    ant Form 常用 api
    antd-design LocaleProvider国际化
  • 原文地址:https://www.cnblogs.com/machaofast/p/2658593.html
Copyright © 2011-2022 走看看