| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.system.query.QueryGenerator; |
| | | //import org.jeecg.modules.base.service.IUnitService; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecgframework.poi.excel.entity.ImportParams; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | .collect(Collectors.toList()); |
| | | return Result.OK(nums); |
| | | } |
| | | /** |
| | | * 导入 |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | LoginUser user= (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | String exceptionInfo = ""; |
| | | int exceptionNum = 0; |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setNeedSave(true); |
| | | try { |
| | | InputStream fis = file.getInputStream(); |
| | | Workbook workbook = new XSSFWorkbook(fis); |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | PrecisionParametersTemplate precisionParametersTemplate = new PrecisionParametersTemplate(); |
| | | Row row1 = sheet.getRow(1); |
| | | Cell cell15 = row1.getCell(5); |
| | | if(ObjectUtils.isNotNull(cell15)&&cell15.getCellType()==CellType.NUMERIC){ |
| | | String num = (int)cell15.getNumericCellValue()+""; |
| | | precisionParametersTemplate.setNum(num); |
| | | EquipmentPrecisionParameters equipmentPrecisionParameters = new EquipmentPrecisionParameters(); |
| | | } |
| | | |
| | | for (Row row : sheet) { |
| | | Cell cell1 = row.getCell(1); |
| | | |
| | | if(row.getRowNum()>4){ |
| | | |
| | | } |
| | | for (Cell cell : row) { |
| | | String cellValue = ""; |
| | | if (cell.getCellType() == CellType.STRING) { |
| | | cellValue = cell.getStringCellValue(); |
| | | } else if (cell.getCellType() == CellType.NUMERIC) { |
| | | cellValue = String.valueOf(cell.getNumericCellValue()); |
| | | } |
| | | // 在这里可以根据您的逻辑处理和清理数据 |
| | | System.out.println("Cell Value: " + cellValue); |
| | | } |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return Result.error("文件导入失败!"); |
| | | } |
| | | // 检查单元格是否在合并单元格范围内 |
| | | private boolean isMergedCell(Sheet sheet, Cell cell) { |
| | | for (CellRangeAddress mergedRegion : sheet.getMergedRegions()) { |
| | | if (mergedRegion.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | // 获取合并单元格的值 |
| | | private String getMergedCellValue(Sheet sheet, Cell cell) { |
| | | for (CellRangeAddress mergedRegion : sheet.getMergedRegions()) { |
| | | if (mergedRegion.isInRange(cell.getRowIndex(), cell.getColumnIndex())) { |
| | | Row firstRow = sheet.getRow(mergedRegion.getFirstRow()); |
| | | Cell firstCell = firstRow.getCell(mergedRegion.getFirstColumn()); |
| | | if (firstCell != null) { |
| | | if (firstCell.getCellType() == CellType.STRING) { |
| | | return firstCell.getStringCellValue(); |
| | | } else if (firstCell.getCellType() == CellType.NUMERIC) { |
| | | return String.valueOf(firstCell.getNumericCellValue()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |