예제 #1
0
        public static OLog Start(string log, ConsoleColor errorColor = ConsoleColor.Red, bool isAddTime = true, int millisecond = 500, string modify = "正在{0}")
        {
            var sp = new StrPlus();

            if (isAddTime)
            {
                sp.Append(string.Format("{0}\t", DateTime.Now.ToString("HH:mm:ss")));
            }
            sp.Append(string.Format(modify + " ", log));
            Console.Write(sp);
            return(new OLog(millisecond, errorColor));
        }
예제 #2
0
        /// <summary>
        ///     生成Excel文件
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="fileName">保存的文件名</param>
        public static void CreateExcel(DataTable dt, string fileName)
        {
            var response = HttpContext.Current.Response;

            response.ContentEncoding = Encoding.GetEncoding("gb2312");
            response.AppendHeader("content-disposition",
                                  "attachment;filename=\"" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls\"");
            response.ContentType = "application/ms-excel";

            var SP = new StrPlus();

            SP.Append("<table border='1' cellspacing='0' cellpadding='0'>");

            SP.Append("<tr>");
            foreach (DataColumn item in dt.Columns)
            {
                SP.AppendFormat(
                    "<td style='font-size: 12px;text-align:center;background-color: #DCE0E2; font-weight:bold;' height='20'>{0}</td>",
                    item.Caption);
            }
            SP.Append("</tr>");


            //定义表对象与行对象,同时用DataSet对其值进行初始化
            foreach (DataRow row in dt.Rows)
            {
                SP.Append("<tr>");

                //在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
                for (var i = 0; i < dt.Columns.Count; i++)
                {
                    SP.AppendFormat("<td style='background-color: #E9ECED;font-size: 12px;'>{0}</td>",
                                    row[i].ToString());
                }
                SP.Append("</tr>");
            }

            SP.Append("</table>");
            response.Write(SP);
            response.End();
        }