public object AddMulitDeparment(IFormCollection files) { string[] colName = new string[] { "公司名称", "部门经理", "部门名称", "员工数量", "部门代码" }; var result = new object(); if (files != null && files.Files.Count > 0) { for (int i = 0; i < files.Files.Count; i++) { var file = files.Files[i]; try { object path = _importExcelUtil.SaveExcel(file); FileInfo fileInfo = new FileInfo((string)path); using (FileStream fs = new FileStream(fileInfo.ToString(), FileMode.Create)) { file.CopyTo(fs); fs.Flush(); } using (ExcelPackage package = new ExcelPackage(fileInfo)) { ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; List <Deparment> successDeparments; if (_importExcelUtil.JudgeCol(worksheet, colName)) { result = new { data = _importExcelUtil.SaveDepToDB(worksheet, out successDeparments) }; System.IO.File.Delete((string)path); foreach (var item in successDeparments) { TransferWorkerDto transferWorkerDto = new TransferWorkerDto { WorkerId = (int)item.ManagerId, DeparmentId = item.Id, StateId = _commonAppService.GetManagerState(item.CompanyId), PositionId = _commonAppService.GetManagerPosition(item.CompanyId) }; _dangAnAppService.TransferWorker(transferWorkerDto); } } } } catch (Exception ex) { result = new { data = ex.Message, fileError = true }; } } } return(result); }