示例#1
0
        /// <summary>
        ///  导出Excel
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="content">The content.</param>
        /// <param name="datetime1">The datetime1.</param>
        /// <param name="datetime2">The datetime2.</param>
        /// Author  : Napoleon
        /// Created : 2015-01-14 14:15:33
        public ActionResult ExcelLog(string userName, string content, string datetime1, string datetime2)
        {
            string fileName = "系统日志" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".xls";
            string filePath = Server.MapPath("../Export/");

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            SystemLog log = new SystemLog();

            log.UserName       = userName;
            log.OperateContent = content;
            datetime1          = string.IsNullOrWhiteSpace(datetime1) ? SqlDateTime.MinValue.ToString() : datetime1;
            datetime2          = string.IsNullOrWhiteSpace(datetime2) ? SqlDateTime.MaxValue.ToString() : datetime2;
            DataTable dt = log.SelectLogTable(datetime1, datetime2);

            string[]     titles     = { "ID", "操作用户", "IP地址", "日志时间", "日志类型", "错误地址", "日志内容" };
            string[]     columns    = { "Id", "UserName", "IpAddress", "OperateTime", "OperateType", "OperateUrl", "OperateContent" };
            MemoryStream fileStream = dt.CreateSheet(titles, columns);

            fileStream.Seek(0, SeekOrigin.Begin);
            fileStream.StreamToFile(filePath + fileName);
            return(Content("../Export/" + fileName));
            //return File(fileStream, "application/vnd.ms-excel", PublicFields.LogExcelName);
        }
示例#2
0
 /// <summary>
 ///  导出Excel
 /// </summary>
 /// <param name="userName">Name of the user.</param>
 /// <param name="content">The content.</param>
 /// <param name="datetime1">The datetime1.</param>
 /// <param name="datetime2">The datetime2.</param>
 /// Author  : Napoleon
 /// Created : 2015-01-14 14:15:33
 public FileResult ExcelLog(string userName, string content, string datetime1, string datetime2)
 {
     SystemLog log = new SystemLog();
     log.UserName = userName;
     log.OperateContent = content;
     datetime1 = string.IsNullOrWhiteSpace(datetime1) ? SqlDateTime.MinValue.ToString() : datetime1;
     datetime2 = string.IsNullOrWhiteSpace(datetime2) ? SqlDateTime.MaxValue.ToString() : datetime2;
     DataTable dt = log.SelectLogTable(datetime1, datetime2);
     string[] titles = { "ID", "操作用户", "IP地址", "日志时间", "日志类型", "错误地址", "日志内容" };
     string[] columns = { "Id", "UserName", "IpAddress", "OperateTime", "OperateType", "OperateUrl", "OperateContent" };
     //string excel = dt.Excel("", columns, titles, false, null, "");
     //MemoryStream fileStream = new MemoryStream(Encoding.Default.GetBytes(excel));
     //return File(fileStream, "application/ms-excel", PublicFields.LogExcelName);
     MemoryStream fileStream = dt.CreateSheet(titles, columns);
     fileStream.Seek(0, SeekOrigin.Begin);
     return File(fileStream, "application/vnd.ms-excel", PublicFields.LogExcelName);
 }
示例#3
0
 /// <summary>
 ///  导出Excel
 /// </summary>
 /// <param name="userName">Name of the user.</param>
 /// <param name="content">The content.</param>
 /// <param name="datetime1">The datetime1.</param>
 /// <param name="datetime2">The datetime2.</param>
 /// Author  : Napoleon
 /// Created : 2015-01-14 14:15:33
 public ActionResult ExcelLog(string userName, string content, string datetime1, string datetime2)
 {
     string fileName = "系统日志" + DateTime.Now.ToString("yyyyMMddhhmmssff") + ".xls";
     string filePath = Server.MapPath("../Export/");
     if (!Directory.Exists(filePath))
     {
         Directory.CreateDirectory(filePath);
     }
     SystemLog log = new SystemLog();
     log.UserName = userName;
     log.OperateContent = content;
     datetime1 = string.IsNullOrWhiteSpace(datetime1) ? SqlDateTime.MinValue.ToString() : datetime1;
     datetime2 = string.IsNullOrWhiteSpace(datetime2) ? SqlDateTime.MaxValue.ToString() : datetime2;
     DataTable dt = log.SelectLogTable(datetime1, datetime2);
     string[] titles = { "ID", "操作用户", "IP地址", "日志时间", "日志类型", "错误地址", "日志内容" };
     string[] columns = { "Id", "UserName", "IpAddress", "OperateTime", "OperateType", "OperateUrl", "OperateContent" };
     MemoryStream fileStream = dt.CreateSheet(titles, columns);
     fileStream.Seek(0, SeekOrigin.Begin);
     fileStream.StreamToFile(filePath + fileName);
     return Content("../Export/" + fileName);
     //return File(fileStream, "application/vnd.ms-excel", PublicFields.LogExcelName);
 }