java读取MultipartFile文件excel文件内容

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);
}
相关推荐
哭哭啼3 分钟前
JAVA服务问题诊断
java·开发语言·jvm
Sayuanni%329 分钟前
SpringBoot 从注解到源码:核心知识点总结
java·spring boot·后端
坚定信念,勇往无前1 小时前
Maven 私有仓库-nexus
java
Minner-Scrapy1 小时前
Scrapy 2.17 源码解析:Scheduler 调度器与磁盘/内存双队列
java·爬虫·python·scrapy·网络爬虫·twisted
晚风醉蝶1 小时前
1-11-奇偶排序-OddEvenSort
java·数据结构·算法
上海魁鲸科技有限公司1 小时前
APS高级排产系统到底有什么用?一文讲清功能、选型与落地建议
前端·microsoft·excel
夏天拐跑了西瓜2 小时前
Spring Cloud 微服务实战(三):一个服务挂了,凭什么拖垮整个系统?Sentinel 限流熔断实战
java·spring cloud·微服务
2601_967264282 小时前
Jetpack Compose 实践指南:从入门到进阶
java·学习
m0_587383002 小时前
社区家政系统开发实战:从需求分析到上线部署全指南
java·spring boot·spring·需求分析
凤山老林3 小时前
动态 i18n 体系落地:Spring Boot 多租户热加载与前后端协同实践
java·spring boot·后端·i18n