public void ExportHealthResult(string templateFilePath, List <ImportResultModel> data) { var excelModel = new ExcelModel(); foreach (var sheet in data) { var excelSheetModel = new ExcelSheetModel(); excelSheetModel.Name = sheet.Title; bool hasExtra = false; for (int row = 0; row < sheet.ErrorRows.Count; row++) { if (sheet.ErrorRows[row].RowIndex == 0) { for (var col = 0; col < sheet.ErrorRows[row].Values.Count; col++) { var cell = new ExcelSheetCellModel(); cell.RowIndex = col + 2; cell.ColumnIndex = 2; cell.Value = sheet.ErrorRows[row].Values[col]; foreach (var error in sheet.ErrorRows[row].ErrorCols) { if (col == error.ColIndex) { cell.Errors.Add(error.Message); } } excelSheetModel.Cells.Add(cell); } hasExtra = true; } else { for (var col = 0; col < sheet.ErrorRows[row].Values.Count; col++) { var cell = new ExcelSheetCellModel(); cell.RowIndex = hasExtra ? row + 8 : row + 9; cell.ColumnIndex = col + 1; cell.Value = sheet.ErrorRows[row].Values[col]; foreach (var error in sheet.ErrorRows[row].ErrorCols) { if (col == error.ColIndex) { cell.Errors.Add(error.Message); } } excelSheetModel.Cells.Add(cell); } } } excelModel.Sheets.Add(excelSheetModel); } _importExportService.ExportWithTemplate(templateFilePath, excelModel); }
public void ExportCompanyEmployees(string templateFilePath, List <ImportResultModel> data) { //将List<ImportResultModel>转成ExcelModel后导出 var excelModel = new ExcelModel(); foreach (var sheet in data) { var excelSheetModel = new ExcelSheetModel(); excelSheetModel.Name = sheet.Title; for (int row = 0; row < sheet.ErrorRows.Count; row++) { for (var col = 0; col < sheet.ErrorRows[row].Values.Count; col++) { var cell = new ExcelSheetCellModel(); cell.RowIndex = row + 2; cell.ColumnIndex = col + 1; cell.Value = sheet.ErrorRows[row].Values[col]; foreach (var error in sheet.ErrorRows[row].ErrorCols) { if (col == error.ColIndex) { cell.Errors.Add(error.Message); } } excelSheetModel.Cells.Add(cell); } } excelModel.Sheets.Add(excelSheetModel); } //_importExportService.Export(templateFilePath, data); _importExportService.ExportWithTemplate(templateFilePath, excelModel); }
public void ExportCheckForm(string filePath, CompanyEmployee emp, string webRootPath = "") { var excelModel = new ExcelModel(); var excelSheet = new ExcelSheetModel(); excelSheet.Name = "Sheet1"; excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "编号", RowIndex = 3, ColumnIndex = 5, Value = DateTime.Now.ToString("yyyyMMddhhmmss"), }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "姓名", RowIndex = 5, ColumnIndex = 2, Value = emp.EmployeeBaseInfo.UserName }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "性别", RowIndex = 5, ColumnIndex = 5, Value = emp.EmployeeBaseInfo.Sex }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "身份证号码", RowIndex = 7, ColumnIndex = 2, Value = emp.EmployeeBaseInfo.IDCard, }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "婚姻状况", RowIndex = 7, ColumnIndex = 5, Value = emp.Married.Name }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "总工龄", RowIndex = 9, ColumnIndex = 2, Value = emp.TotalWorkMonthes.HasValue ? emp.TotalWorkMonthes.Value.ToString() : "?" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "接害工龄", RowIndex = 9, ColumnIndex = 5, Value = emp.AdverseMonthes.HasValue ? emp.AdverseMonthes.Value.ToString() : "?" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "毒害种类和名称", RowIndex = 12, ColumnIndex = 1, Value = emp.AdverseFactor }); if (!string.IsNullOrEmpty(emp.Company.CompanyStamp)) { excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "用人单位签章", RowIndex = 12, ColumnIndex = 4, Value = webRootPath + emp.Company.CompanyStamp.Replace("/", "\\"), ValueType = ExcelValueType.Image, }); } if (emp.EmployeeBaseInfo.WorkHistories != null && emp.EmployeeBaseInfo.WorkHistories.Count > 0) { var startRow = 21; foreach (var history in emp.EmployeeBaseInfo.WorkHistories) { excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "起止日期", RowIndex = startRow, ColumnIndex = 1, Value = string.Format("{0}-{1}", history.EntryDate.HasValue ? history.EntryDate.Value.ToString("yyyy-MM-dd") : "?", history.LeaveDate.HasValue ? history.LeaveDate.Value.ToString("yyyy-MM-dd") : "?") }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "工作单位", RowIndex = startRow, ColumnIndex = 2, Value = history.CompanyName }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "车间", RowIndex = startRow, ColumnIndex = 3, Value = history.Department }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "工种", RowIndex = startRow, ColumnIndex = 4, Value = history.WorkType }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "有害因素", RowIndex = startRow, ColumnIndex = 5, Value = history.AdverseFactor }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "防护措施", RowIndex = startRow, ColumnIndex = 6, Value = history.ProtectType }); startRow++; } } excelModel.Sheets.Add(excelSheet); _importExportService.ExportWithTemplate(filePath, excelModel); }
public void ExportSpecificationResult(string filePath, List <MSDS_Specification> data) { var excelModel = new ExcelModel(); var excelSheet = new ExcelSheetModel(); excelSheet.Name = "Sheet1"; if (data.Count > 0) { int rowIndex = 3; foreach (var entity in data) { #region int colIndex = 1; excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "序号", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = (rowIndex - 2).ToString() }); string checkStr = string.Empty; switch (entity.SpecificationCheck?.Status) { case 1: checkStr = "待审批"; break; case 2: checkStr = "已审批"; break; case 3: checkStr = "被驳回"; break; default: checkStr = "未审批"; break; } excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "审批状态", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = checkStr }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "产品名", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Name ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "产品名(中文)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.CN_Name ?? " " }); string strState = string.Empty; switch (entity.Product_State) { case 1: strState = "气体"; break; case 2: strState = "液体"; break; case 3: strState = "固态"; break; case 4: strState = "气溶胶"; break; case 5: strState = "凝胶"; break; case 6: strState = "膏状物"; break; case 7: strState = "其他"; break; default: strState = "N/A"; break; } excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "状态", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = strState }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "CAS号", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.CASCode ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "UN编号", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_UN.HasValue? entity.Product_UN.Value.ToString():" " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "有害化学品", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.UnHazardousChemical.HasValue ? (entity.UnHazardousChemical.Value ? "是" : "否") : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "供应商名称", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Supplier_Name ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "供应商电话", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Supplier_Phone ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "供应商24小时应急电话", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Supplier_UrgencyCall ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "危险性分类", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.GHS_Category ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "警告词", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.GHS_Warning ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "危害简述", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_HazardousDescription ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "防范说明(预防)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.GHS_DefenceDes_Values ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "防范说明(响应)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.GHS_DealDES_Values ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "防范说明(储存)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.GHS_StoreDes_Values ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "爆炸物", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsExplosive?"是":"否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "易燃物", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsFlammable ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "腐蚀", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsCorrosive ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "长期危害健康", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsHealthHazard ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "剧毒", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsToxic ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "氧化剂", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsOxidizing ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "高压气体", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsGasUnderPressure ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "刺激性", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsIrritant ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "环境危害", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.IsDangerousToEnvironment ? "是" : "否" }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(眼面部)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_FaceAndEye ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(手部)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_Hand ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(呼吸保护)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_Breathing ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(足部)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_Foot ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(身体)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_Body ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "个人防护用品(其他防护)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Protection_Other ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(眼面部沾染)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_ET_FaceAndEye ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(皮肤手部沾染)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_ET_SkinAndHand ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(吸入)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_ET_Inhalation ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(食入)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_ET_Ingestion ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(应急消防)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_FireProtection ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(泄漏处置)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_LeakageHanding ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(作业安全)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_OperationSecure ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(储存要求)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_StoreRequirement ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(废弃物处置)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_WasteHanding ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "急救措施(备注)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Product_Note ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "运输信息(当地法规)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Policie_Local ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "运输信息(联合国法规)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Policie_UN ?? " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "沸点(液体) ℃", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.BoilingPoint_Liquid.HasValue? entity.BoilingPoint_Liquid.Value.ToString():" " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "闪点 ℃", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.FlashingPoint.HasValue ? entity.FlashingPoint.Value.ToString() : " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "燃烧极限范围(下限)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.BurningLimit_Min.HasValue ? entity.BurningLimit_Min.Value.ToString() : " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "燃烧极限范围(上限)", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.BurningLimit_Max.HasValue ? entity.BurningLimit_Max.Value.ToString() : " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "蒸汽压 mmHg", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.VaporPressure.HasValue ? entity.VaporPressure.Value.ToString() : " " }); excelSheet.Cells.Add(new ExcelSheetCellModel() { Title = "创建时间", RowIndex = rowIndex, ColumnIndex = colIndex++, Value = entity.Create_Date.HasValue ? entity.Create_Date.Value.ToString("yyyy-MM-dd HH:mm:ss") : "N/A" }); #endregion rowIndex++; } } excelModel.Sheets.Add(excelSheet); _importExportService.ExportWithTemplate(filePath, excelModel); }