• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
深水是沉默
别自制压力,我们没有必要跟着时间走, 只需跟着心态和能力走 随缘 尽力 问心无愧,其他的,交给天。
博客园    首页    新随笔    联系   管理    订阅  订阅
Java 导入excel获取表格信息
public ResponseFindPage<Student> findPage(@RequestParam("file") MultipartFile file) {
ResponseFindPage<Student> rfp = new ResponseFindPage<Student>();
String fileName = file.getOriginalFilename();
System.out.println(fileName);

Workbook workbook = null;
try {
InputStream in = file.getInputStream();
workbook = new XSSFWorkbook(in);
//workbook = WorkbookFactory.create(new File(String.valueOf(file)));
} catch (IOException e) {
e.printStackTrace();
}
//获取一张表
Sheet sheet = workbook.getSheetAt(0);
for (int i = 1; i <= sheet.getLastRowNum(); i++) {//跳过第一行,取得其他行数据
Row row = sheet.getRow(i);//取得第i行数据
Student student = new Student();
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);//取得第j列数据
cell.setCellType(CellType.STRING);
String value = cell.getStringCellValue();
System.out.print(i + " " + j + " " + value + " ");
}
if (StringUtils.isNotBlank(student.getPhone())) {
students.add(student);
}
}
rfp.setData(students);
return rfp;
}
posted on 2021-03-17 18:08  深水是沉默  阅读(314)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3