java读取MultipartFile文件excel文件内容
java
@PostMapping("/importData")
public AjaxResult importData(@RequestPart(name = "file", value = "file") MultipartFile file) throws Exception
{
ExcelUtil<CarModelVo> util = new ExcelUtil<>(CarModelVo.class);
// 获取excel文件数据流
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);
}