首页 > 编程语言 > 详细

Java 导入excel获取表格信息

时间:2021-03-17 22:41:38      阅读:32      评论:0      收藏:0      [点我收藏+]
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;
}

Java 导入excel获取表格信息

原文:https://www.cnblogs.com/xiaobug/p/14550985.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!