public HttpResponseMessage ExportExamStuExcel([FromBody] ExportPaper m) { var eInfo = MongoDbHelper.FindOne <E_Info>(m.ExamID, DbName.E_Info); if (eInfo == null) { return(ResultHelper.Failed("未查到当前考试")); } var filter = new BsonDocument(); filter.Add("eid", eInfo._id); if (!string.IsNullOrEmpty(m.School)) { int id = -1; if (int.TryParse(m.School, out id)) { filter.Add("sid", m.School); } else { filter.Add("snm", m.School); } } var pps = MongoDbHelper.GetPagedList1 <Pp_Nm, string>(DbName.Pp_Nm, 0, 0, filter, w => w.sid); List <string> data = ExcelBLL.GetPaperColumn1(eInfo); List <string> data1 = new List <string>(); for (int i = 0; i < eInfo.sbs.Count; i++) { data1.Add(eInfo.sbs[i].sbnm); } DataTable dt = new DataTable(); for (int j = 0; j < data.Count; j++) { dt.Columns.Add(data[j]); } for (int i = 0; i < pps.Count; i++) { DataRow dr = dt.NewRow(); dr[0] = pps[i].sid; dr[1] = pps[i].snm; for (int j = 0; j < eInfo.sbs.Count; j++) { var sbnm = pps[i].sbnms.Where(w => w.sbid == eInfo.sbs[j]._id).FirstOrDefault(); dr[2 + j * 3] = sbnm == null ? 0 : sbnm.sct; dr[3 + j * 3] = sbnm == null ? 0 : sbnm.ac; dr[4 + j * 3] = sbnm == null ? 0 : sbnm.sct - sbnm.ac; } dt.Rows.Add(dr); } string file = ExcelBLL.BuildPaperExcel(data1.ToArray(), dt); string url = RequestContext.Url.Request.RequestUri.Authority + "\\" + file; return(ResultHelper.OK(url)); }