poi 导入excel 并显示到页面

前几天需要做一个群发message的功能 然后在网上搜了好久,做好之后就想着自己总结一下, 需求就是导入excel 然后解析出excel中内容并显示到页面, 首先是将excel 导入 其实也就是上传到服务器,在截图一中,

 

然后就是 读取excel 

在pom.xml中配置

<artifactId> poi-ooxml </artifactId>

 <version>3.9</version> 

 

然后读取

 

 

  1. try
  2. {
  3. InputStream input = new FileInputStream (path)
  4. XSSFWorkbook workBook = new XSSFWorkbook(input);
  5. XSSFSheet sheet = workBook.getSheetAt(0);
  6. if (sheet != null)
  7. {
  8. for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++)
  9. {
  10. XSSFRow row = sheet.getRow(i);
  11. for (int j = 0; j < row.getPhysicalNumberOfCells(); j++)
  12. {
  13. XSSFCell cell = row.getCell(j);
  14. String cellStr = cell.toString();
  15. }
  16. }
  17. }

然后就可以获得数据了

你可能感兴趣的:(poi 导入excel 并显示到页面)