java读取MultipartFile文件excel文件内容
@PostMapping("/importData")
public AjaxResult importData(@RequestPart(name = "file", value = "file") MultipartFile file) throws Exception
{
ExcelUtil<CarModelVo> util = new ExcelUtil<>(CarModelVo.class);
InputStream is = file.getInputStream();
Workbook wb = WorkbookFactory.create(is);
Sheet sheet = wb.getSheetAt(0);
List<VehicleModelVo> vehicleModelVos = new ArrayList<>();
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
Row row = sheet.getRow(i);
String deptNo = row.getCell(0).getStringCellValue();
String deptName = row.getCell(1).getStringCellValue();
String pushTime = row.getCell(2).getStringCellValue();
int model1 = (int) row.getCell(5).getNumericCellValue();
VehicleModelVo v1 = new VehicleModelVo();
v1.setDeptNo(deptNo);
v1.setDeptName(deptName);
v1.setDirection(direction);
v1.setQuantity(model1);
v1.setPushTime(pushTime);
vehicleModelVos.add(v1);
}
return AjaxResult.success(vehicleModelVos);
}