示例#1
0
        public JsonResult ExportAll()
        {
            var sql = @" select u.ID as UserId,u.Name as UserName,us.Score,us.CreateTime,us.UpdateTime  FROM [WaterSupplySecurity].[dbo].[UserScore] us inner join [dbo].[User] u on u.ID = us.UserID  ";

            var dt = DbHelperSQL.Query(sql).Tables[0];

            DataTable dtExport = new DataTable();

            dtExport.Columns.Add("用户ID");
            dtExport.Columns.Add("用户姓名");
            dtExport.Columns.Add("分数");
            dtExport.Columns.Add("开始时间");
            dtExport.Columns.Add("结束时间");

            foreach (DataRow d in dt.Rows)
            {
                DataRow drExport = dtExport.NewRow();
                drExport["用户ID"] = d["UserId"];
                drExport["用户姓名"] = d["UserName"];
                drExport["分数"]   = d["Score"];
                drExport["开始时间"] = d["CreateTime"].ToString();
                drExport["结束时间"] = d["UpdateTime"].ToString();
                dtExport.Rows.Add(drExport);
            }

            var msg = "";

            ExcelService.DataTableToExcel(dtExport, out msg, "所有分数汇总_" + DateTime.Now.ToString("yyyyMMddHHmmss"));

            return(Json("", JsonRequestBehavior.AllowGet));
        }