zoukankan      html  css  js  c++  java
  • C# .net 导出

     /// <summary>
            /// 导出
            /// </summary>
            /// <returns></returns>
            /// 
            public void ExportData()
            {
                string strTotal = "";
                string title = "";
                string meta = "<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/>";
                StringBuilder builder = new StringBuilder();
                builder.Append(meta);
                builder.Append("<table border=\"1\" style=\"font-size:12px; line-height:30px; \">");
                builder.Append("<tr><td colspan='5' style=\"text-align:center;height:30px;font-weight:bolder; font-size:16px;\"> ");
                builder.Append(title + "(" + DateTime.Now.ToString("yyyy-MM-dd") + ")");
                builder.Append("</td></tr>");
                builder.Append("<tr>");
                //builder.AppendFormat("<td style='text-align:center;height:30px; 50px'>ID</td>");
                //builder.AppendFormat("<td style='text-align:center;height:30px; 100px'题</td>");
                //builder.AppendFormat("<td style='text-align:center;height:30px; 100px'>动ID</td>");
                builder.AppendFormat("<td style='text-align:center;height:30px; 150px'>名称</td>");
                //builder.AppendFormat("<td style='text-align:center;height:30px; 100px'>名人ID</td>");
                builder.AppendFormat("<td style='text-align:center;height:30px; 150px'人姓名</td>");
                builder.AppendFormat("<td style='text-align:center;height:30px; 100px'>部</td>");
                builder.AppendFormat("<td style='text-align:center;height:30px; 150px'>联方式</td>");
                builder.AppendFormat("<td style='text-align:center;height:30px; 150px'>他</td>");
                builder.Append("</tr>");
                builder.Append(strTotal);
                builder.Append("</table>");
                System.Web.HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(title + "" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", Encoding.UTF8));
                HttpContext.Current.Response.Charset = "UTF-8";
                HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
                HttpContext.Current.Response.ContentType = "application/ms-excel";
                HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=gb2312>");
                // 把文件流发送到客户端  
                System.Web.HttpContext.Current.Response.Write(builder.ToString());
                // 停止页面的执行   
                System.Web.HttpContext.Current.Response.End();
            }
    
  • 相关阅读:
    015.Delphi插件之QPlugins,FMX插件窗口
    014.Delphi插件之QPlugins,MDI窗口
    013.Delphi插件之QPlugins,模块化代码示例
    012.Delphi插件之QPlugins,多实例内嵌窗口服务
    011.Delphi插件之QPlugins,延时加载服务
    010.Delphi插件之QPlugins,遍历服务接口
    009.Delphi插件之QPlugins,服务的热插拔
    008.Delphi插件之QPlugins,服务的两种调用方法
    007.Delphi插件之QPlugins,插件的卸载和重新加载
    006.Delphi插件之QPlugins,多服务演示
  • 原文地址:https://www.cnblogs.com/TNSSTAR/p/2853038.html
Copyright © 2011-2022 走看看