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();
            } 
  • 相关阅读:
    System Verilog 片断
    如何避免covergroup中出现错误
    一种FPGA图像处理算法的快速验证方式
    什么才是一个feature to be test?
    我的第一份vPlan衍变路线
    思想误区解答:请专注于DUT的功能(全部为菜鸟个人总结不保证正确)
    谈谈验证中的SystemVerilog和CPP//转载
    ResourceBundleViewResolver
    springmvc json数据返回前台,中文乱码
    将字符串中间的某段长度替换成固定的值
  • 原文地址:https://www.cnblogs.com/machaofast/p/2658593.html
Copyright © 2011-2022 走看看