import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileInputStream; import java.io.InputStream; public class ExcelReader { public static void main(String[] args) { String filepath = "path/to/excel/file.xlsx"; try { InputStream is = new FileInputStream(filepath); Workbook workbook = new XSSFWorkbook(is); Sheet sheet = workbook.getSheetAt(0); for (Row row : sheet) { for (Cell cell : row) { CellType cellType = cell.getCellType(); if (cellType == CellType.STRING) { System.out.print(cell.getStringCellValue() + " "); } else if (cellType == CellType.NUMERIC) { System.out.print(cell.getNumericCellValue() + " "); } } System.out.println(); } workbook.close(); } catch (Exception e) { e.printStackTrace(); } } }


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