From 414d8e938349358b43e6ff485f7ca819d10b7a41 Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期三, 07 九月 2022 10:50:29 +0800 Subject: [PATCH] 软件excel解析 --- src/main/java/com/whyc/service/SoftwareService.java | 42 ++++++++++++++++++++++++------------------ 1 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/whyc/service/SoftwareService.java b/src/main/java/com/whyc/service/SoftwareService.java index 5c8cb7c..99a5483 100644 --- a/src/main/java/com/whyc/service/SoftwareService.java +++ b/src/main/java/com/whyc/service/SoftwareService.java @@ -1,13 +1,8 @@ package com.whyc.service; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.github.pagehelper.PageHelper; -import com.whyc.dto.Response; -import com.whyc.mapper.SoftwareMapper; import com.whyc.pojo.Software; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.IOException; @@ -20,7 +15,7 @@ @Autowired private SoftwareMapper mapper; - public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException { + public List<Software> excelParse(InputStream inputStream) throws IOException, InvalidFormatException, ParseException { List<Software> softwareList = new LinkedList<>(); Workbook workbook = null; @@ -36,26 +31,37 @@ common.setFileName(sheet.getRow(2).getCell(2).getStringCellValue()); String typeStr = sheet.getRow(3).getCell(2).getStringCellValue(); String[] typeArr = typeStr.split(" "); + for (int i = 0; i < typeArr.length; i++) { + //excel鍗曞厓鏍间腑鐨勨湐瀵瑰簲瀛楃 + if(typeArr[i].contains("镁")){ + common.setType(typeArr[i].trim()); + break; + } + } + common.setVersion(sheet.getRow(4).getCell(2).getStringCellValue()); + common.setBasedVersion(sheet.getRow(4).getCell(4).getStringCellValue()); + + common.setOwner(sheet.getRow(5).getCell(2).getStringCellValue()); + String filingDateStr = sheet.getRow(5).getCell(4).getStringCellValue(); + Date filingDate = DateUtil.YYYY_MM_DD.parse(filingDateStr); + common.setFilingDate(filingDate); + //鏈�鍚庝竴琛�,鍙栧彂甯冭鏄� + common.setReleaseNotes(sheet.getRow(lastRowNum).getCell(2).getStringCellValue()); //绗�8琛屽紑濮�,鍊掓暟绗�2琛屾埅姝� - for (int i = 0; i < lastRowNum+1; i++) { + int applyModelNum = lastRowNum + 1 - 8; + for (int i = 0; i < applyModelNum; i++) { Software software = new Software(); + BeanUtils.copyProperties(common,software); //鍙栫3鍒�,绗�5鍒� - for (int j = 1; j < cellNum; j++) { - Row row = sheet.getRow(i); - Cell cell = row.getCell(j); - if(j == 2){ - cell.setCellType(Cell.CELL_TYPE_STRING); - } - String cellValue = cell.getStringCellValue(); + software.setApplyMaterialCode(sheet.getRow(8+i).getCell(2).getStringCellValue()); + software.setApplyModel(sheet.getRow(8+i).getCell(4).getStringCellValue()); - switch (j){ - - } - } softwareList.add(software); } + softwareList = softwareList.stream().filter(software -> !software.getApplyMaterialCode().equals("")).collect(Collectors.toList()); + return softwareList; } -- Gitblit v1.9.1