public async Task <ActionResult> ImportUser() //导入用户 { string file_user = Server.MapPath("~") + "Files\\per.xlsx"; DataTable dt; dt = OpenXmlExcelHelper.Import(file_user); List <Organization> orglist = db.Organizations.ToList(); foreach (DataRow dr in dt.Rows) { var l = orglist.Where(i => i.temp_id == dr[3].ToString().Trim()).FirstOrDefault(); var user = new ApplicationUser() { UserName = dr[0].ToString().Trim() }; user.TrueName = dr[1].ToString().Trim() + dr[2].ToString().Trim(); user.OrganizationID = l.ID; var result = await UserManager.CreateAsync(user, "000000"); } var json = new { okMsg = "ok" }; return(Json(json, "text/html", JsonRequestBehavior.AllowGet)); }
public string ImportOrg() //导入组织机构 { string file_org = Server.MapPath("~") + "Files\\org.xlsx"; DataTable dt; dt = OpenXmlExcelHelper.Import(file_org); string file_orgrel = Server.MapPath("~") + "Files\\orgrel.xlsx"; DataTable dtrel; dtrel = OpenXmlExcelHelper.Import(file_orgrel); foreach (DataRow dr in dt.Rows) { // sss+=dr[0].ToString()+""+dr[1].ToString()+dr[2].ToString()+"<br>"; Organization org1 = new Organization(); org1.orgName = dr[2].ToString(); org1.orgShortName = dr[1].ToString(); org1.temp_id = dr[0].ToString(); foreach (DataRow drrel in dtrel.Rows) { if (dr[0].ToString().Trim() == drrel[1].ToString().Trim()) { org1.temp_pid = drrel[0].ToString().Trim(); continue; } } db.Organizations.Add(org1); db.SaveChanges(); } return("ok"); }