Excel文件格式校验
@ApiOperation(value = "模板导入校验") @PostMapping("/excelTemplateVerify") public RestResponse<String> excelTemplateVerify(@RequestParam("file") MultipartFile file, @RequestParam("scope") String scope){ try{ DominantScope dominantScope = JSONObject.parseObject(scope,DominantScope.class); if(!file.isEmpty()) { InputStream inputStream = file.getInputStream(); inputStream = FileMagic.prepareToCheckMagic(inputStream); FileMagic fm = FileMagic.valueOf(inputStream); //校验excel是否是xlsx格式 if(!FileMagic.OOXML.equals(fm)) { throw new RuntimeException("文件格式不正确!"); } serviceLocator.getBalanceService().excelTemplateVerify(inputStream, dominantScope); } }catch (RuntimeException | IOException e){ e.printStackTrace(); return RestResponse.failure("校验失败" + e.getMessage(),null); } return RestResponse.success("校验通过"); }