一:导入依赖:
cn.hutool
hutool-all
${hutool.version}
org.apache.poi
poi-ooxml
${poi.version}
org.apache.poi
poi
${poi.version}
org.apache.poi
poi-ooxml-schemas
${poi.version}
二,编写代码(事例)
public HttpResult importFile(@RequestParam("multipartFile") MultipartFile multipartFile) throws IOException {
ExcelReader reader = ExcelUtil.getReader(multipartFile.getInputStream());
reader.addHeaderAlias("料号","partNum");
reader.addHeaderAlias("备件料号名称","partSpareName");
reader.addHeaderAlias("备件规格","partNorms");
reader.addHeaderAlias("安全库存","safetyStock");
reader.addHeaderAlias("入库数量","warehousingNum");
reader.addHeaderAlias("适用设备","fitEqp");
reader.addHeaderAlias("库位","location");
List eqpInfos = reader.readAll(SparePart.class);
eqpInfos.stream().map(a->{
a.setCompanyId(Convert.toLong(systemFeignService.getCompanyIdFeign(RequestContext.getInstance().getCompanyName()).getData()));
SparePart one = sparePartService.getOne(new LambdaQueryWrapper().eq(SparePart::getPartNum, a.getPartNum()));
SparePart sparePart=new SparePart();
BeanUtils.copyProperties(a,sparePart);
boolean save = sparePartService.save(sparePart);
one.setWarehousingNum(one.getWarehousingNum()+ a.getWarehousingNum());
boolean save = sparePartService.updateById(one);