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();
            } 
  • 相关阅读:
    C++中的指针常量与常量指针
    Ubuntu16.04下安装ROS kinetic常见问题及解决方法
    关于安装ROS的资料备份
    后台模块--删除、修改用户信息
    客车网上售票系统--查询、添加用户
    客车网上售票系统--登录
    客车网上售票系统--需求分析(一)
    简单的邮件发送器(二)
    简单的邮件发送器(一)
    在CMD上用telnet远程登录发送邮件测试记录
  • 原文地址:https://www.cnblogs.com/machaofast/p/2658593.html
Copyright © 2011-2022 走看看