利用 poi 获取 xlsx 文件内容信息
需要的jar包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| InputStream inputStream = file.getInputStream(); XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
int sheet = workbook.getNumberOfSheets();
workbook.getSheetAt(0)
private String cellinfo(XSSFSheet sheet, int x, int y){ XSSFRow row = sheet.getRow(x); XSSFCell cell = row.getCell(y); if(cell == null){ return null; } if (cell.getCellType() == CellType.NUMERIC && DateUtil.isCellDateFormatted(cell)){ Date dateCellValue = cell.getDateCellValue(); return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, dateCellValue); } cell.setCellType(CellType.STRING); return cell.getStringCellValue(); }
private void d(XSSFSheet sheet){ int rows = sheet.getLastRowNum() + 1; for (int i = 0; i < rows; i++) { XSSFRow row = sheet.getRow(i); int firstCellNum = row.getLastCellNum(); for (int j = 0; j < firstCellNum; j++) { XSSFCell cell = row.getCell(j); if(cell != null){ continue; } cell.setCellType(CellType.STRING); String cellValue = cell.getStringCellValue(); System.out.println("cellValue = " + cellValue); } } }
|