import org.apache.poi.ss.usermodel.*; import java.io.FileInputStream; import java.io.IOException; public class ReadExcelFile { public static void main(String[] args) { try (FileInputStream file = new FileInputStream("path/to/excel-file.xlsx")) { Workbook workbook = WorkbookFactory.create(file); Sheet sheet = workbook.getSheetAt(0); for (Row row : sheet) { for (Cell cell : row) { switch (cell.getCellType()) { 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.print("\t"); } } System.out.println(); } } catch (IOException e) { e.printStackTrace(); } } } <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>


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