前几天需要做一个群发message的功能 然后在网上搜了好久,做好之后就想着自己总结一下, 需求就是导入excel 然后解析出excel中内容并显示到页面, 首先是将excel 导入 其实也就是上传到服务器,在截图一中,
然后就是 读取excel
在pom.xml中配置
<artifactId> poi-ooxml </artifactId>
<version>3.9</version>
然后读取
- try
- {
- InputStream input = new FileInputStream (path)
- XSSFWorkbook workBook = new XSSFWorkbook(input);
- XSSFSheet sheet = workBook.getSheetAt(0);
- if (sheet != null)
- {
- for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++)
- {
- XSSFRow row = sheet.getRow(i);
- for (int j = 0; j < row.getPhysicalNumberOfCells(); j++)
- {
- XSSFCell cell = row.getCell(j);
- String cellStr = cell.toString();
- }
- }
- }
然后就可以获得数据了