一、Maven引入依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
二、导入文件
String xls = "/video.xlsx";
FileInputStream fis = new FileInputStream(xls);
Workbook workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(0);
int count = sheet.getLastRowNum();
System.out.println(count);
for (int i = 1; i <= count; i++) {
Row row = sheet.getRow(i);
System.out.println(row.getCell(1).getStringCellValue());
}
注意事项:
sheet.getLastRowNum() 获取的是最后一行行号,第一行从0开始,等于总行数-1