From ec8a22b7ea91d9e845216ef573d0436aaa9993ef Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期六, 05 七月 2025 20:45:33 +0800 Subject: [PATCH] 保养规范点检导入 --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java | 6 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java | 18 + lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java | 497 ++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 384 insertions(+), 137 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java index 317a494..e8d2bc8 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java @@ -7,18 +7,13 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.jeecg.common.api.vo.FileUploadResult; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.base.controller.JeecgController; -import org.jeecg.common.util.FileUtil; import org.jeecg.modules.eam.constant.BusinessCodeConst; import org.jeecg.modules.eam.constant.MaintenanceCategoryEnum; import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; @@ -36,7 +31,6 @@ import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.entity.ImportParams; -import org.jeecgframework.poi.util.PoiPublicUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -281,6 +275,18 @@ return super.exportXls(request, eamMaintenanceStandard, EamMaintenanceStandard.class, "淇濆吇鏍囧噯"); } + @PostMapping("/import") + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); + for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { + // 鑾峰彇涓婁紶鏂囦欢瀵硅薄 + MultipartFile file = entity.getValue(); + eamMaintenanceStandardService.importPointInspectionExcel(file); + } + return Result.ok("瀵煎叆鎴愬姛"); + } + /** * 閫氳繃excel瀵煎叆鏁版嵁 * diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java index 643d231..61bef31 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java @@ -7,6 +7,7 @@ import org.jeecg.modules.eam.entity.EamMaintenanceStandard; import org.jeecg.modules.eam.request.EamMaintenanceStandardRequest; import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -81,4 +82,9 @@ */ Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo); + + /** + * 鐐规琛ㄥ鍏ュ叆鍙� + */ + public Result<?> importPointInspectionExcel(MultipartFile file); } diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java index b83c998..724dfbf 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java @@ -9,16 +9,12 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.jeecg.weibo.exception.BusinessException; import org.apache.commons.lang3.StringUtils; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.ss.usermodel.*; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; import org.flowable.task.api.Task; -import org.jeecg.common.api.vo.FileUploadResult; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; @@ -37,7 +33,7 @@ import org.jeecg.modules.eam.service.IEamEquipmentService; import org.jeecg.modules.eam.service.IEamMaintenanceStandardDetailService; import org.jeecg.modules.eam.service.IEamMaintenanceStandardService; -import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo; +import org.jeecg.modules.eam.vo.*; import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness; import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService; import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI; @@ -53,6 +49,8 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -524,132 +522,369 @@ /*瀵煎叆鏂囦欢--------------------------寮�濮�*/ /** - * 瀵煎叆鐐规琛ㄦ暟鎹� - * @param file Excel鏂囦欢 - * @return 瀵煎叆缁撴灉 - */ -// public Result<?> importInspectionData(MultipartFile file) { -// int successCount = 0; -// -// try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { -// Sheet sheet = workbook.getSheetAt(0); -// // 1. 瑙f瀽琛ㄥご淇℃伅 -// Map<String, String> header = parseHeader(sheet, errors); -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// return new ImportResult(successCount, errors); -// } + * 鐐规琛ㄥ鍏ュ叆鍙� + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Result<?> importPointInspectionExcel(MultipartFile file) { + try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { + Sheet sheet = workbook.getSheetAt(0); + + // 鎻愬彇鍚嶇О + String name = extractInspectionTitle(file) + "鐐规琛�"; + + // 1. 鎻愬彇璁惧淇℃伅 + EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet); + if (eamMaintenanceStandard == null) { + throw new BusinessException("璁惧淇℃伅鎻愬彇澶辫触"); + } + + eamMaintenanceStandard.setStandardName(name); + eamMaintenanceStandardMapper.insert(eamMaintenanceStandard); + + // 2. 鎻愬彇姣忔棩鐐规椤圭洰 + List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard); + + // 3. 鎻愬彇鍛ㄤ繚鍏婚」鐩� + List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard); + + // 鍚堝苟骞朵繚瀛樻墍鏈夐」鐩� + List<EamMaintenanceStandardDetail> allDetails = new ArrayList<>(); + allDetails.addAll(dailyDetails); + allDetails.addAll(weeklyDetails); + + if (!CollectionUtils.isEmpty(allDetails)) { + eamMaintenanceStandardDetailService.saveBatch(allDetails); + } + + return Result.OK("鐐规琛ㄥ鍏ユ垚鍔�"); + + } catch (Exception e) { + throw new BusinessException("鐐规琛ㄥ鍏ュけ璐�: " + e.getMessage()); + } + } /** - * 瑙f瀽琛ㄥご淇℃伅 + * 鎻愬彇鐐规琛ㄦ爣棰� + */ + private String extractInspectionTitle(MultipartFile file) { + try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { + Sheet sheet = workbook.getSheetAt(0); + Row firstRow = sheet.getRow(0); + + if (firstRow == null) { + return "鏈壘鍒版爣棰�"; + } + + Cell firstCell = firstRow.getCell(0); + if (firstCell == null) { + return ""; + } + + String title = getCellStringValue(firstCell); + return extractTextBeforeInspection(title); + + } catch (Exception e) { + return ""; + } + } + + /** + * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧 */ -// private Map<String, String> parseHeader(Sheet sheet, List<ImportError> errors) { -// Map<String, String> header = new HashMap<>(); -// try { -// Row headerRow = sheet.getRow(0); -// // 绀轰緥锛氱涓�琛岋細璁惧鍚嶇О:鍓茬偓 鍨嬪彿:gta001 缁熶竴缂栧彿:xc001 -// String cellValue = getCellStringValue(headerRow.getCell(0)); -// -// // 浣跨敤姝e垯琛ㄨ揪寮忚В鏋愬叧閿俊鎭� -// Pattern pattern = Pattern.compile("璁惧鍚嶇О[:锛歖(\\S+)\\s+鍨嬪彿[:锛歖(\\S+)\\s+缁熶竴缂栧彿[:锛歖(\\S+)\\s+鏃ユ湡[:锛歖(\\S+)\\s+鍗曚綅[:锛歖(\\S+)"); -// Matcher matcher = pattern.matcher(cellValue); -// -// if (matcher.find()) { -// header.put("deviceName", matcher.group(1)); -// header.put("deviceModel", matcher.group(2)); -// header.put("deviceCode", matcher.group(3)); -// header.put("inspectionMonth", matcher.group(4)); -// header.put("unit", matcher.group(5)); -// } else { -// errors.add(new ImportError("琛ㄥご鏍煎紡閿欒", cellValue, 1)); -// } -// } catch (Exception e) { -// errors.add(new ImportError("瑙f瀽琛ㄥご寮傚父", e.getMessage(), 1)); -// } -// return header; -// } -// -// /** -// * 瑙f瀽姣忔棩鐐规椤圭洰 -// */ -// private List<InspectionItem> parseDailyItems(Sheet sheet, List<ImportError> errors) { -// List<InspectionItem> items = new ArrayList<>(); -// -// // 鐐规椤圭洰浠庣3琛屽紑濮嬶紙搴忓彿浠�1寮�濮嬶級 -// int startRow = 2; -// int rowNum = startRow; -// -// try { -// // 鎵惧埌姣忔棩鐐规琛ㄧ殑缁撴潫浣嶇疆锛堢淮鎶よ矗浠讳汉绛惧瓧锛� -// while (rowNum <= sheet.getLastRowNum()) { -// Row row = sheet.getRow(rowNum); -// if (row == null) { -// rowNum++; -// continue; -// } -// -// // 鍒ゆ柇鏄惁鍒拌揪缁撴潫浣嶇疆 -// String sequenceValue = getCellStringValue(row.getCell(0)); -// if ("9".equals(sequenceValue) || "缁存姢璐d换浜虹瀛�".contains(sequenceValue)) { -// break; -// } -// -// // 瑙f瀽椤圭洰琛� -// InspectionItem item = new InspectionItem(); -// item.setSequence(Integer.parseInt(sequenceValue)); -// item.setProjectName(getCellStringValue(row.getCell(1))); -// item.setRequirement(getCellStringValue(row.getCell(2))); -// -// items.add(item); -// rowNum++; -// } -// } catch (Exception e) { -// errors.add(new ImportError("瑙f瀽姣忔棩椤圭洰寮傚父", e.getMessage(), rowNum + 1)); -// } -// -// return items; -// } -// -// /** -// * 瑙f瀽鍛ㄤ繚鍏婚」鐩� -// */ -// private List<InspectionItem> parseWeeklyItems(Sheet sheet, List<ImportError> errors) { -// List<InspectionItem> items = new ArrayList<>(); -// -// try { -// // 瀹氫綅鍛ㄤ繚鍏绘爣棰樿锛堣鍙�11锛� -// int startRow = 10; -// -// // 浠庣12琛屽紑濮嬫槸鍛ㄤ繚鍏婚」鐩� -// for (int rowNum = startRow + 1; rowNum <= sheet.getLastRowNum(); rowNum++) { -// Row row = sheet.getRow(rowNum); -// if (row == null) continue; -// -// String sequenceValue = getCellStringValue(row.getCell(0)); -// -// // 閬囧埌缁撴潫鏍囧織鍒欏仠姝㈣В鏋� -// if ("鍛ㄤ繚鍏绘搷浣滆�呮墽琛�".contains(sequenceValue)) break; -// -// try { -// InspectionItem item = new InspectionItem(); -// item.setSequence(Integer.parseInt(sequenceValue)); -// item.setProjectName(getCellStringValue(row.getCell(1))); -// item.setStandard(getCellStringValue(row.getCell(2))); -// item.setRequirement(getCellStringValue(row.getCell(3))); // 鎵ц璁板綍 -// -// items.add(item); -// } catch (Exception e) { -// errors.add(new ImportError("瑙f瀽鍛ㄤ繚鍏婚」鐩紓甯�", e.getMessage(), rowNum + 1)); -// } -// } -// } catch (Exception e) { -// errors.add(new ImportError("瀹氫綅鍛ㄤ繚鍏婚」鐩紓甯�", e.getMessage(), 0)); -// } -// -// return items; -// } + private String extractTextBeforeInspection(String title) { + if (StringUtils.isBlank(title)) { + return ""; + } + + int index = title.indexOf("鐐规琛�"); + return index > 0 ? title.substring(0, index).trim() : title; + } + + /** + * 鎻愬彇璁惧淇℃伅 + */ + private EamMaintenanceStandard extractDeviceInfo(Sheet sheet) { + Row headerRow = sheet.getRow(0); + if (headerRow == null) { + return null; + } + + String headerText = getCellStringValue(headerRow.getCell(0)); + if (StringUtils.isBlank(headerText)) { + return null; + } + + EamMaintenanceStandard standard = new EamMaintenanceStandard(); + standard.setEquipmentName(extractField(headerText, "璁惧鍚嶇О[:锛歖\\s*(\\S+)")); + standard.setEquipmentId(extractField(headerText, "璁惧鍨嬪彿[:锛歖\\s*(\\S+)")); + standard.setStandardCode(extractField(headerText, "缁熶竴缂栧彿[:锛歖\\s*(\\S+)")); + + // 鏃ユ湡澶勭悊 + String dateStr = extractField(headerText, "鏃ユ湡[:锛歖\\s*(\\S+)"); + if (StringUtils.isNotBlank(dateStr)) { + try { + // 鏀寔澶氱鏃ユ湡鏍煎紡 + Date date = parseDate(dateStr); + standard.setDesignTime(date); + standard.setInitialDate(date); + } catch (ParseException ignored) { + + } + } + + standard.setMaintenanceCategory("POINT_INSPECTION"); + standard.setPeriodUnit("澶�"); + standard.setStandardStatus(MaintenanceStandardStatusEnum.START.name()); + standard.setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1); + standard.setDelFlag(0); + + return standard; + } + + /** + * 瑙f瀽鏃ユ湡瀛楃涓� + */ + private Date parseDate(String dateStr) throws ParseException { + // 灏濊瘯澶氱鏃ユ湡鏍煎紡 + String[] patterns = { + "yyyy骞碝M鏈�", + "yyyy-MM", + "yyyy/MM", + "yyyyMM", + "yyyy骞碝鏈�" + }; + + for (String pattern : patterns) { + try { + SimpleDateFormat sdf = new SimpleDateFormat(pattern); + sdf.setLenient(false); + return sdf.parse(dateStr); + } catch (ParseException e) { + // 灏濊瘯涓嬩竴涓牸寮� + } + } + + throw new ParseException("鏃犳硶瑙f瀽鏃ユ湡: " + dateStr, 0); + } + + /** + * 鎻愬彇姣忔棩鐐规椤圭洰 + */ + private List<EamMaintenanceStandardDetail> extractDailyItems(Sheet sheet, EamMaintenanceStandard standard) { + return extractItems(sheet, standard, "鐐规椤圭洰", "瀹屾垚鏁版嵁/瑕佹眰", "DAY_INSPECTION"); + } + + /** + * 鎻愬彇鍛ㄤ繚鍏婚」鐩� + */ + private List<EamMaintenanceStandardDetail> extractWeeklyItems(Sheet sheet, EamMaintenanceStandard standard) { + return extractItems(sheet, standard, "鍛ㄤ繚鍏婚」鐩�", "妫�鏌ユ爣鍑�", "WEEK_INSPECTION"); + } + + /** + * 閫氱敤椤圭洰鎻愬彇鏂规硶 + */ + private List<EamMaintenanceStandardDetail> extractItems(Sheet sheet, EamMaintenanceStandard standard, + String primaryHeader, String secondaryHeader, + String itemCategory) { + int[] section = findTableSection(sheet, primaryHeader, secondaryHeader); + if (section == null) { + return Collections.emptyList(); + } + + List<EamMaintenanceStandardDetail> details = new ArrayList<>(); + for (int rowIdx = section[0]; rowIdx <= section[1]; rowIdx++) { + Row row = sheet.getRow(rowIdx); + if (row == null || isEmptyRow(row)) { + continue; + } + + // 纭繚绗竴鍒楁槸搴忓彿锛堟暟瀛楋級 + Cell seqCell = row.getCell(0); + if (seqCell == null || seqCell.getCellType() != CellType.NUMERIC) { + continue; + } + + // 鍒涘缓椤圭洰璇︽儏 + EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail(); + detail.setStandardId(standard.getId()); + detail.setItemName(getCellStringValue(row.getCell(1))); + detail.setItemCategory(itemCategory); + + // 鏍规嵁椤圭洰绫诲瀷璁剧疆闇�姹傚瓧娈� + if ("DAY_INSPECTION".equals(itemCategory)) { + detail.setItemDemand(getCellStringValue(row.getCell(2))); + } else if ("WEEK_INSPECTION".equals(itemCategory)) { + detail.setItemDemand(getCellStringValue(row.getCell(2))); + } + + details.add(detail); + } + + return details; + } + + /** + * 鏌ユ壘琛ㄦ牸鍖哄煙 + */ + private int[] findTableSection(Sheet sheet, String primaryHeader, String secondaryHeader) { + for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) { + Row row = sheet.getRow(rowIdx); + if (row == null) continue; + + if (isHeaderRow(row, primaryHeader, secondaryHeader)) { + int startRow = rowIdx + 1; + int endRow = findDataEnd(sheet, startRow); + return new int[]{startRow, endRow}; + } + } + return null; + } + + /** + * 妫�鏌ユ槸鍚︿负琛ㄥご琛� + */ + private boolean isHeaderRow(Row row, String header1, String header2) { + boolean foundHeader1 = false; + boolean foundHeader2 = false; + + for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { + Cell cell = row.getCell(colIdx); + if (cell == null) continue; + + String cellValue = getCellStringValue(cell); + if (cellValue.contains(header1)) foundHeader1 = true; + if (cellValue.contains(header2)) foundHeader2 = true; + } + + return foundHeader1 && foundHeader2; + } + + /** + * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆 + */ + private int findDataEnd(Sheet sheet, int startRow) { + for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { + Row row = sheet.getRow(rowIdx); + if (row == null) return rowIdx - 1; + + // 妫�鏌ユ槸鍚︾粨鏉熸爣蹇楄锛堝绛惧瓧琛岋級 + if (isSignatureRow(row)) { + return rowIdx - 1; + } + + // 妫�鏌ユ槸鍚︽柊鐨勮〃澶村紑濮� + if (isNewHeaderStart(row)) { + return rowIdx - 1; + } + } + return sheet.getLastRowNum(); + } + + /** + * 璇嗗埆绛惧瓧琛岀壒寰� + */ + private boolean isSignatureRow(Row row) { + for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { + Cell cell = row.getCell(colIdx); + if (cell == null) continue; + + String value = getCellStringValue(cell); + if (value.contains("绛惧瓧") || value.contains("璐d换浜�") || + value.contains("鎵ц") || value.contains("纭")) { + return true; + } + } + return false; + } + + /** + * 璇嗗埆鏂拌〃澶村紑濮� + */ + private boolean isNewHeaderStart(Row row) { + for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { + Cell cell = row.getCell(colIdx); + if (cell == null) continue; + + String value = getCellStringValue(cell); + if ("搴忓彿".equals(value) || "鐐规椤圭洰".equals(value) || "鍛ㄤ繚鍏婚」鐩�".equals(value)) { + return true; + } + } + return false; + } + + /** + * 妫�鏌ヨ鏄惁涓虹┖ + */ + private boolean isEmptyRow(Row row) { + if (row == null) return true; + for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) { + Cell cell = row.getCell(colIdx); + if (cell != null && cell.getCellType() != CellType.BLANK) { + String value = getCellStringValue(cell); + if (StringUtils.isNotBlank(value)) { + return false; + } + } + } + return true; + } + + /** + * 浣跨敤姝e垯鎻愬彇瀛楁 + */ + private String extractField(String text, String regex) { + if (StringUtils.isBlank(text)) return ""; + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(text); + return matcher.find() ? matcher.group(1) : ""; + } + + /** + * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊� + */ + private String getCellStringValue(Cell cell) { + if (cell == null) return ""; + + switch (cell.getCellType()) { + case STRING: + return cell.getStringCellValue().trim(); + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) { + return new SimpleDateFormat("yyyy骞碝M鏈�").format(cell.getDateCellValue()); + } + return String.valueOf((int) cell.getNumericCellValue()); + case BOOLEAN: + return String.valueOf(cell.getBooleanCellValue()); + case FORMULA: + return handleFormulaCell(cell); + default: + return ""; + } + } + + /** + * 澶勭悊鍏紡鍗曞厓鏍� + */ + private String handleFormulaCell(Cell cell) { + try { + FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); + CellValue cellValue = evaluator.evaluate(cell); + + if (cellValue == null) return ""; + + switch (cellValue.getCellType()) { + case STRING: return cellValue.getStringValue(); + case NUMERIC: return String.valueOf((int) cellValue.getNumberValue()); + case BOOLEAN: return String.valueOf(cellValue.getBooleanValue()); + default: return ""; + } + } catch (Exception e) { + return ""; + } + } /*瀵煎叆鏂囦欢--------------------------缁撴潫*/ } -- Gitblit v1.9.3