public void readExcel(MultipartFile file,HttpServletResponse respon) throws IOException{ POIFSFileSystem sf=new POIFSFileSystem(file.getInputStream()); HSSFWorkbook book=new HSSFWorkbook(sf); HSSFSheet sheet=book.getSheetAt(0); int row=sheet.getLastRowNum(); HSSFRow rowObj=null; for(int i=0;i<=row;i++){ rowObj=sheet.getRow(i); if(null!=rowObj&&null!=rowObj.getCell(0)&&StringUtils.isNotBlank(getValue(rowObj.getCell(0)))){ HSSFCell cell=rowObj.getCell(0); String str=getValue(cell); } } } public String getValue(HSSFCell cell){ DecimalFormat df = new DecimalFormat("0"); String value=""; if(null!=cell&&StringUtils.isNotBlank(cell.toString())){ switch(cell.getCellType()){ case HSSFCell.CELL_TYPE_NUMERIC : value = df.format(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING : value = cell.getRichStringCellValue().getString(); break; case HSSFCell.CELL_TYPE_FORMULA : value = cell.getCellFormula(); break; } } return value; }
来源:https://www.cnblogs.com/shizijie/p/9364660.html