| | |
| | | |
| | | // 1. æå设å¤ä¿¡æ¯ |
| | | EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet); |
| | | if (eamMaintenanceStandard == null) { |
| | | if (eamMaintenanceStandard == null || eamMaintenanceStandard.getEquipmentId() == null) { |
| | | return Result.error("设å¤ä¿¡æ¯æå失败"); |
| | | } else { |
| | | if (eamMaintenanceStandard.getEquipmentId() == null) { |
| | | return Result.error("设å¤ä¿¡æ¯æå失败"); |
| | | } |
| | | } |
| | | |
| | | eamMaintenanceStandard.setStandardName(name); |
| | | |
| | | EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.START.name()); |
| | | // æ£æ¥éå¤ |
| | | EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), |
| | | eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.START.name()); |
| | | if (exist != null) { |
| | | return Result.error(name + ": è®¾å¤æ åå·²åå¨ï¼ä¸è½é夿·»å "); |
| | | } |
| | | |
| | | eamMaintenanceStandardMapper.insert(eamMaintenanceStandard); |
| | | |
| | | // 2. æåæ¯æ¥ç¹æ£é¡¹ç® |
| | | List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard); |
| | | Map<Integer, String> rowErrors = new HashMap<>(); |
| | | |
| | | // 2. æåæ¯æ¥ç¹æ£é¡¹ç®ï¼ä¼å空è¡åç»ææ è®°å¤çï¼ |
| | | List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard, rowErrors); |
| | | if (dailyDetails.isEmpty()) { |
| | | return Result.error("æªæ¾å°æ¯æ¥ç¹æ£é¡¹ç®"); |
| | | } |
| | | |
| | | // 3. æåå¨ä¿å
»é¡¹ç® |
| | | List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard); |
| | | List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard, rowErrors); |
| | | if (weeklyDetails.isEmpty()) { |
| | | return Result.error("æªæ¾å°å¨ä¿å
»é¡¹ç®"); |
| | | } |
| | |
| | | eamMaintenanceStandardDetailService.saveBatch(allDetails); |
| | | } |
| | | |
| | | SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type"); |
| | | |
| | | if (sysParams != null) { |
| | | if (sysParams.getSettingValue().equals("1")) { |
| | | //触åä¿å
»æµç¨ |
| | | SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type"); |
| | | if (sysParams != null && sysParams.getSettingValue().equals("1")) { |
| | | eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name()); |
| | | eamMaintenanceStandardMapper.updateById(eamMaintenanceStandard); |
| | | } |
| | | } else { |
| | | return Result.error("æªæ¾å°ä¿å
»æµç¨å¯¼å
¥ç¸å
³é
ç½®,请è系管çå"); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * æåæ¯æ¥ç¹æ£é¡¹ç® |
| | | */ |
| | | 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.setItemCode(Integer.parseInt(getCellStringValue(row.getCell(0)))); |
| | | 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("责任人") || |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * ä½¿ç¨æ£åæååæ®µ |
| | | */ |
| | | private String extractField(String text, String regex) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
æ ¼åç¬¦ä¸²å¼ |
| | | * æåæ¯æ¥ç¹æ£é¡¹ç® |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractDailyItems(Sheet sheet, EamMaintenanceStandard standard, Map<Integer, String> rowErrors) { |
| | | // 使ç¨å¤å
³é®è¯å¹é
|
| | | String[] primaryHeaders = {"ç¹æ£é¡¹ç®", "æ¥å¸¸ç¹æ£", "æ¯æ¥æ£æ¥"}; |
| | | String[] secondaryHeaders = {"å®ææ°æ®/è¦æ±", "æ£æ¥æ å", "è¦æ±"}; |
| | | return extractItems(sheet, standard, primaryHeaders, secondaryHeaders, "DAY_INSPECTION", rowErrors); |
| | | } |
| | | |
| | | /** |
| | | * æåå¨ä¿å
»é¡¹ç® |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractWeeklyItems(Sheet sheet, EamMaintenanceStandard standard, Map<Integer, String> rowErrors) { |
| | | // 使ç¨å¤å
³é®è¯å¹é
|
| | | String[] primaryHeaders = {"å¨ä¿å
»é¡¹ç®", "å¨ä¿å
»", "æ¯å¨ä¿å
»"}; |
| | | String[] secondaryHeaders = {"æ£æ¥æ å", "ä¿å
»è¦æ±", "æ å"}; |
| | | return extractItems(sheet, standard, primaryHeaders, secondaryHeaders, "WEEK_INSPECTION", rowErrors); |
| | | } |
| | | |
| | | /** |
| | | * æ ¸å¿æ¹è¿ï¼ä¼åè¡¨æ ¼åºåè¯å«åæ°æ®æå |
| | | */ |
| | | private List<EamMaintenanceStandardDetail> extractItems(Sheet sheet, |
| | | EamMaintenanceStandard standard, |
| | | String[] primaryHeaders, |
| | | String[] secondaryHeaders, |
| | | String itemCategory, |
| | | Map<Integer, String> rowErrors) { |
| | | |
| | | // 1. å®ä½è¡¨æ ¼åºåï¼ç²¾ç¡®å¹é
è¡¨å¤´ï¼ |
| | | int startRow = findHeaderRow(sheet, primaryHeaders, secondaryHeaders); |
| | | if (startRow == -1) { |
| | | rowErrors.put(-1, "æªæ¾å°" + Arrays.toString(primaryHeaders) + "表头åºå"); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | int endRow = findDataEnd(sheet, startRow + 1, "å¨ä¿å
»é¡¹ç®"); |
| | | |
| | | // æåæ¥å¿ï¼å®é
ä½¿ç¨æ¶å¯ä»¥å»æï¼ |
| | | System.out.println("æååºå: " + (startRow + 1) + "è¡å°" + (endRow + 1) + "è¡"); |
| | | |
| | | // 2. æåæ°æ®è¡ |
| | | List<EamMaintenanceStandardDetail> details = new ArrayList<>(); |
| | | for (int rowIdx = startRow + 1; rowIdx <= endRow; rowIdx++) { |
| | | Row row = sheet.getRow(rowIdx); |
| | | if (row == null) continue; |
| | | |
| | | try { |
| | | // åºå·åå¤ç |
| | | Cell seqCell = row.getCell(0); |
| | | if (seqCell == null || seqCell.getCellType() == CellType.BLANK) { |
| | | continue; |
| | | } |
| | | |
| | | // è·ååºå·å¼ï¼æ¯ææ°ååææ¬æ ¼å¼ï¼ |
| | | int seqValue = 0; |
| | | try { |
| | | if (seqCell.getCellType() == CellType.NUMERIC) { |
| | | seqValue = (int) seqCell.getNumericCellValue(); |
| | | } else if (seqCell.getCellType() == CellType.STRING) { |
| | | seqValue = Integer.parseInt(seqCell.getStringCellValue().trim()); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | rowErrors.put(rowIdx + 1, "åºå·æ ¼å¼é误"); |
| | | continue; |
| | | } |
| | | |
| | | // 项ç®åç§°åï¼ç¬¬äºåï¼ |
| | | Cell nameCell = row.getCell(1); |
| | | if (nameCell == null || nameCell.getCellType() == CellType.BLANK) { |
| | | continue; |
| | | } |
| | | String itemName = getCellStringValue(nameCell).trim(); |
| | | |
| | | // è¦æ±/æ ååï¼ç¬¬ä¸åï¼ |
| | | String demand = ""; |
| | | if (row.getLastCellNum() >= 3) { |
| | | Cell demandCell = row.getCell(2); |
| | | if (demandCell != null) { |
| | | demand = getCellStringValue(demandCell).trim(); |
| | | } |
| | | } |
| | | |
| | | // å建详æ
对象 |
| | | EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail(); |
| | | detail.setStandardId(standard.getId()); |
| | | detail.setItemCode(seqValue); |
| | | detail.setItemName(itemName); |
| | | detail.setItemDemand(demand); |
| | | detail.setItemCategory(itemCategory); |
| | | details.add(detail); |
| | | |
| | | } catch (Exception e) { |
| | | rowErrors.put(rowIdx + 1, "è§£æé误: " + e.getMessage()); |
| | | } |
| | | } |
| | | return details; |
| | | } |
| | | |
| | | /** |
| | | * è·åè¡ä¸ææåå
æ ¼çåç¬¦ä¸²å¼ |
| | | */ |
| | | private List<String> getRowStringValues(Row row) { |
| | | List<String> values = new ArrayList<>(); |
| | | if (row == null) return values; |
| | | |
| | | for (int cellIdx = 0; cellIdx < row.getLastCellNum(); cellIdx++) { |
| | | Cell cell = row.getCell(cellIdx); |
| | | if (cell != null) { |
| | | values.add(getCellStringValue(cell)); |
| | | } else { |
| | | values.add(""); // 对äºç©ºåå
æ ¼æ·»å 空å符串 |
| | | } |
| | | } |
| | | return values; |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
æ ¼å符串å¼ï¼å¢å¼ºå
¬å¼å¤çï¼ |
| | | */ |
| | | private String getCellStringValue(Cell cell) { |
| | | if (cell == null) return ""; |
| | | if (cell == null) { |
| | | return ""; |
| | | } |
| | | // ä¿æä¸åï¼ä½æ·»å æ°åç±»åå¤ç |
| | | if (cell.getCellType() == CellType.NUMERIC) { |
| | | // æ´æ°å¤ç |
| | | double num = cell.getNumericCellValue(); |
| | | if (num == (int) num) { |
| | | return String.valueOf((int) num); |
| | | } |
| | | return String.valueOf(num); |
| | | } |
| | | switch (cell.getCellType()) { |
| | | case STRING: |
| | | return cell.getStringCellValue().trim(); |
| | |
| | | case BOOLEAN: |
| | | return String.valueOf(cell.getBooleanCellValue()); |
| | | case FORMULA: |
| | | return handleFormulaCell(cell); |
| | | return getFormulaCellValue(cell); |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çå
¬å¼åå
æ ¼ |
| | | * ç²¾ç¡®æ¥æ¾è¡¨å¤´è¡ |
| | | */ |
| | | private String handleFormulaCell(Cell cell) { |
| | | private int findHeaderRow(Sheet sheet, String[] primaryHeaders, String[] secondaryHeaders) { |
| | | for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) { |
| | | Row row = sheet.getRow(rowIdx); |
| | | if (row == null) continue; |
| | | |
| | | String rowText = getRowStringValues(row).stream().collect(Collectors.joining()); |
| | | |
| | | // æ£æ¥ä¸»æ é¢å坿 é¢ |
| | | boolean hasPrimary = false; |
| | | boolean hasSecondary = false; |
| | | |
| | | for (String header : primaryHeaders) { |
| | | if (rowText.contains(header)) { |
| | | hasPrimary = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | for (String header : secondaryHeaders) { |
| | | if (rowText.contains(header)) { |
| | | hasSecondary = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (hasPrimary && hasSecondary) { |
| | | return rowIdx; |
| | | } |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¾æ°æ®ç»æä½ç½®ï¼æ ¹æ®æ¨çExcelç»æä¼åï¼ |
| | | */ |
| | | private int findDataEnd(Sheet sheet, int startRow, String nextSectionKeyword) { |
| | | int consecutiveEmptyRows = 0; |
| | | final int MAX_EMPTY_ROWS = 3; |
| | | |
| | | for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { |
| | | Row row = sheet.getRow(rowIdx); |
| | | |
| | | // å
³é®æ¹è¿1ï¼ç©ºè¡å¤ç |
| | | if (isEssentiallyEmpty(row)) { |
| | | consecutiveEmptyRows++; |
| | | if (consecutiveEmptyRows >= MAX_EMPTY_ROWS) { |
| | | return rowIdx - consecutiveEmptyRows; |
| | | } |
| | | continue; |
| | | } else { |
| | | consecutiveEmptyRows = 0; |
| | | } |
| | | |
| | | // å
³é®æ¹è¿2ï¼ç»ææ è®°æ£æµ |
| | | String rowText = getRowStringValues(row).stream().collect(Collectors.joining()); |
| | | |
| | | // æ ¹æ®æ¨çExcelç»æï¼ç¾åè¡æç¹å®æ ¼å¼ |
| | | if (rowText.contains("ç»´æ¤è´£ä»»äººç¾å")) { |
| | | return rowIdx - 1; |
| | | } |
| | | |
| | | // æ£æµä¸ä¸ä¸ªåºåçå¼å§ï¼å¦å¨ä¿å
»é¡¹ç®ï¼ |
| | | if (StringUtils.isNotBlank(nextSectionKeyword) && |
| | | rowText.contains(nextSectionKeyword)) { |
| | | return rowIdx - 1; |
| | | } |
| | | } |
| | | return sheet.getLastRowNum(); |
| | | } |
| | | |
| | | /** |
| | | * 夿æ¡ä»¶ï¼å两å为空å³è§ä¸ºç©ºè¡ |
| | | */ |
| | | private boolean isEssentiallyEmpty(Row row) { |
| | | if (row == null) return true; |
| | | |
| | | // æ£æ¥åºå·å |
| | | Cell indexCell = row.getCell(0); |
| | | if (indexCell != null && indexCell.getCellType() != CellType.BLANK) { |
| | | return false; |
| | | } |
| | | |
| | | // æ£æ¥é¡¹ç®åç§°å |
| | | Cell nameCell = row.getCell(1); |
| | | if (nameCell != null && nameCell.getCellType() != CellType.BLANK) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * è·åå
¬å¼åå
æ ¼å¼ |
| | | */ |
| | | private String getFormulaCellValue(Cell cell) { |
| | | try { |
| | | FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator(); |
| | | Workbook workbook = cell.getSheet().getWorkbook(); |
| | | FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); |
| | | CellValue cellValue = evaluator.evaluate(cell); |
| | | |
| | | if (cellValue == null) return ""; |
| | | |
| | | if (cellValue == null) { |
| | | return ""; |
| | | } |
| | | switch (cellValue.getCellType()) { |
| | | case STRING: |
| | | return cellValue.getStringValue(); |
| | |
| | | return ""; |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("è§£æå
¬å¼åå
æ ¼å¤±è´¥"); |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | |
| | | private int findDataEnd(Sheet sheet, int startRow) { |
| | | int consecutiveEmptyRows = 0; |
| | | final int MAX_EMPTY_ROWS = 2; |
| | | boolean foundData = false; |
| | | |
| | | for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) { |
| | | Row row = sheet.getRow(rowIdx); |
| | | |
| | | // å
³é®ä¼å1ï¼å
æ£æ¥æ¯å¦ä¸ºç©ºè¡ |
| | | if (isEmptyRow(row)) { |
| | | consecutiveEmptyRows++; |
| | | if (consecutiveEmptyRows >= MAX_EMPTY_ROWS) { |
| | | return foundData ? rowIdx - consecutiveEmptyRows : startRow; |
| | | } |
| | | continue; |
| | | } else { |
| | | consecutiveEmptyRows = 0; |
| | | } |
| | | |
| | | // å
³é®ä¼å2ï¼ä¸¥æ ¼éå®ç»ææ è®°çè¯å«æ¡ä»¶ |
| | | if (isStrongEndMarker(row)) { |
| | | return foundData ? rowIdx - 1 : startRow; |
| | | } |
| | | |
| | | // å
³é®ä¼å3ï¼æ è®°å·²æ¾å°æææ°æ® |
| | | foundData = true; |
| | | } |
| | | return sheet.getLastRowNum(); |
| | | } |
| | | |
| | | // å¢å¼ºçç»ææ è®°è¯å« |
| | | private boolean isStrongEndMarker(Row row) { |
| | | String rowText = String.join("", getRowStringValues(row)).toLowerCase(); |
| | | |
| | | return |
| | | // 精确å¹é
ç¾åç¹å¾ï¼åºç°å¨è¡é¦ï¼ |
| | | (rowText.startsWith("ç»´æ¤è´£ä»»äººç¾å") || |
| | | rowText.startsWith("æ§è¡äººç¾å")) || |
| | | // 精确å¹é
æ°æ¿åæ é¢ |
| | | rowText.matches("^\\s*å¨ä¿å
»é¡¹ç®\\s*$") || |
| | | rowText.contains("年度ä¿å
»é¡¹ç®"); |
| | | } |
| | | |
| | | // ç©ºè¡æ£æµä¼åï¼å
许é¨ååä¸ºç©ºï¼ |
| | | private boolean isEmptyRow(Row row) { |
| | | if (row == null) return true; |
| | | // åªæ£æ¥å3åï¼åºå·å+项ç®å+è¦æ±ï¼ |
| | | for (int cellIdx = 0; cellIdx < Math.min(3, row.getLastCellNum()); cellIdx++) { |
| | | Cell cell = row.getCell(cellIdx); |
| | | if (cell != null && cell.getCellType() != CellType.BLANK) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | /*导å
¥ç¹æ£æä»¶Excel--------------------------ç»æ*/ |
| | | |
| | | /*导å
¥äºä¿ä¸ä¿æä»¶Excel--------------------------å¼å§*/ |