<dependencies> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> </dependencies> import org.apache.poi.ss.usermodel.*; import java.io.FileInputStream; import java.io.IOException; public class ExcelReader { public static void main(String[] args) { try (FileInputStream fis = new FileInputStream("example.xlsx"); Workbook workbook = WorkbookFactory.create(fis)) { Sheet sheet = workbook.getSheetAt(0); for (Row row : sheet) { for (Cell cell : row) { CellType cellType = cell.getCellType(); switch (cellType) { case STRING: System.out.print(cell.getStringCellValue() + "\t"); break; case NUMERIC: System.out.print(cell.getNumericCellValue() + "\t"); break; case BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); break; default: } } System.out.println(); } } catch (IOException e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文