阅读:4663
回复:8
|
[综合]批量导入用户和组织的功能有吗 ?
如题,有这个功能吗?如果有,有模板么?在哪里导入?
|
1楼#
发布于:2017-01-22 14:06
帖内置顶 – H3BPM – 2017-02-09 09:52
有Excel导入组织架构的模板和关键代码
前台代码: <div> <asp:FileUpload ID="FileUpload7" runat="server" Width="200px" /><div> 组织信息导入 <asp:TextBox runat="server" ID="TextBox3" Width="100px"/> <asp:Button ID="Button7" runat="server" Text="导入" Width="100px" OnClick="Button7_Click" /> </div> </div> 后台代码: protected void Button7_Click(object sender, EventArgs e) { IWorkbook workbook = null; if (FileUpload7.HasFile) { string upfile = Server.MapPath("") + "/Temp/" + FileUpload7.PostedFile.FileName; if (!Directory.Exists(Server.MapPath("") + "/Temp/")) { Directory.CreateDirectory(Server.MapPath("") + "/Temp/"); } FileUpload7.PostedFile.SaveAs(upfile); string newpath = upfile; using (FileStream fs = File.OpenRead(newpath)) //打开myxls.xls文件 { if (FileUpload7.PostedFile.FileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(fs); else if (FileUpload7.PostedFile.FileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(fs); #region 导入组织信息 ISheet sheet = workbook.GetSheetAt(0); //读取当前表数据 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row != null&&row.Cells.Count>0) { #region 导入单位信息 var code = row.Cells[0].StringCellValue.Trim(); var parentid = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID; var name = row.Cells[2].StringCellValue.Trim(); var unit = new OThinker.Organization.OrganizationUnit() { ObjectID = Guid.NewGuid().ToString(), Code = code, CompanyID = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID, Name = name, ParentID = parentid, // Sort Key SortKey = j, // 类型 CategoryID = null }; // 写入服务器 var result = OThinker.Organization.HandleResult.SUCCESS; if (OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUnitByCode(code) != null) { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.UpdateUnit(null, unit); } else { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.AddUnit(null, unit); } if (result != OThinker.Organization.HandleResult.SUCCESS) { OThinker.H3.WorkSheet.AppUtility.Engine.LogWriter.Write(name); } #endregion } } #endregion #region 导入用户信息 sheet = workbook.GetSheetAt(1); //读取当前表数据 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row != null && row.Cells.Count > 0) { #region 导入单位信息 var oucode = row.Cells[0].StringCellValue.Trim(); var code = row.Cells[1].StringCellValue.Trim(); var parentou = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUnitByCode(oucode); var name = row.Cells[2].StringCellValue.Trim(); var employeenumber = row.Cells[3].ToString().Trim().Replace(" ", ""); var birthday = row.Cells[4].DateCellValue; var email = row.Cells[5].ToString().Trim(); var officemobile = row.Cells[6]==null?"": row.Cells[6].ToString().Trim(); var unit = new OThinker.Organization.User() { ObjectID = Guid.NewGuid().ToString(), Code = code, CompanyID = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID, Name = name, ParentID = parentou == null ? OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID : parentou.ObjectID, // Sort Key SortKey = j, // 类型 CategoryID = null, EmployeeNumber = employeenumber, OfficePhone = officemobile, Email = email, Birthday = birthday }; // 写入服务器 OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS; if (OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUserByEmployeeNumber(code) != null) { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.UpdateUnit(null, unit); } else { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.AddUnit(null, unit); } if (result != OThinker.Organization.HandleResult.SUCCESS) { OThinker.H3.WorkSheet.AppUtility.Engine.LogWriter.Write(name); } #endregion } } #endregion File.Delete(upfile); } } } |
|
2楼#
发布于:2017-01-18 17:03
|
|
|
4楼#
发布于:2017-01-20 16:07
如果没有现成的AD用户,就做个EXCEL表导入数据到数据库。
|
|
5楼#
发布于:2017-01-20 16:09
|
|
|
7楼#
发布于:2017-01-22 14:06
有Excel导入组织架构的模板和关键代码
前台代码: <div> <asp:FileUpload ID="FileUpload7" runat="server" Width="200px" /><div> 组织信息导入 <asp:TextBox runat="server" ID="TextBox3" Width="100px"/> <asp:Button ID="Button7" runat="server" Text="导入" Width="100px" OnClick="Button7_Click" /> </div> </div> 后台代码: protected void Button7_Click(object sender, EventArgs e) { IWorkbook workbook = null; if (FileUpload7.HasFile) { string upfile = Server.MapPath("") + "/Temp/" + FileUpload7.PostedFile.FileName; if (!Directory.Exists(Server.MapPath("") + "/Temp/")) { Directory.CreateDirectory(Server.MapPath("") + "/Temp/"); } FileUpload7.PostedFile.SaveAs(upfile); string newpath = upfile; using (FileStream fs = File.OpenRead(newpath)) //打开myxls.xls文件 { if (FileUpload7.PostedFile.FileName.IndexOf(".xlsx") > 0) // 2007版本 workbook = new XSSFWorkbook(fs); else if (FileUpload7.PostedFile.FileName.IndexOf(".xls") > 0) // 2003版本 workbook = new HSSFWorkbook(fs); #region 导入组织信息 ISheet sheet = workbook.GetSheetAt(0); //读取当前表数据 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row != null&&row.Cells.Count>0) { #region 导入单位信息 var code = row.Cells[0].StringCellValue.Trim(); var parentid = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID; var name = row.Cells[2].StringCellValue.Trim(); var unit = new OThinker.Organization.OrganizationUnit() { ObjectID = Guid.NewGuid().ToString(), Code = code, CompanyID = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID, Name = name, ParentID = parentid, // Sort Key SortKey = j, // 类型 CategoryID = null }; // 写入服务器 var result = OThinker.Organization.HandleResult.SUCCESS; if (OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUnitByCode(code) != null) { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.UpdateUnit(null, unit); } else { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.AddUnit(null, unit); } if (result != OThinker.Organization.HandleResult.SUCCESS) { OThinker.H3.WorkSheet.AppUtility.Engine.LogWriter.Write(name); } #endregion } } #endregion #region 导入用户信息 sheet = workbook.GetSheetAt(1); //读取当前表数据 for (int j = 1; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row != null && row.Cells.Count > 0) { #region 导入单位信息 var oucode = row.Cells[0].StringCellValue.Trim(); var code = row.Cells[1].StringCellValue.Trim(); var parentou = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUnitByCode(oucode); var name = row.Cells[2].StringCellValue.Trim(); var employeenumber = row.Cells[3].ToString().Trim().Replace(" ", ""); var birthday = row.Cells[4].DateCellValue; var email = row.Cells[5].ToString().Trim(); var officemobile = row.Cells[6]==null?"": row.Cells[6].ToString().Trim(); var unit = new OThinker.Organization.User() { ObjectID = Guid.NewGuid().ToString(), Code = code, CompanyID = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID, Name = name, ParentID = parentou == null ? OThinker.H3.WorkSheet.AppUtility.Engine.Organization.Company.CompanyID : parentou.ObjectID, // Sort Key SortKey = j, // 类型 CategoryID = null, EmployeeNumber = employeenumber, OfficePhone = officemobile, Email = email, Birthday = birthday }; // 写入服务器 OThinker.Organization.HandleResult result = OThinker.Organization.HandleResult.SUCCESS; if (OThinker.H3.WorkSheet.AppUtility.Engine.Organization.GetUserByEmployeeNumber(code) != null) { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.UpdateUnit(null, unit); } else { result = OThinker.H3.WorkSheet.AppUtility.Engine.Organization.AddUnit(null, unit); } if (result != OThinker.Organization.HandleResult.SUCCESS) { OThinker.H3.WorkSheet.AppUtility.Engine.LogWriter.Write(name); } #endregion } } #endregion File.Delete(upfile); } } } |
|
8楼#
发布于:2017-01-22 14:10
Excel整理模板
图片:QQ截图20170122141110.png |
|
9楼#
发布于:2018-05-27 08:35
|
|