try {标签:文件,sheet,读取,excel,System,cell,println,row,out From: https://www.cnblogs.com/YCL-/p/16821221.html
// 创建工作簿
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream("E:\\test.xlsx"));
System.out.println("Workbook对象:" + xssfWorkbook);
// 读取第一个工作表
XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
System.out.println("sheet对象:" + sheet);
// 获取最后一行的num,即总行数。此处从0开始计数
int maxRow = sheet.getLastRowNum();
System.out.println("总行数为:" + (maxRow + 1));
for (int row = 0; row <= maxRow; row++) {
for (int cell = 0; cell <= sheet.getRow(row).getLastCellNum() - 1; cell++) {
//row代表行 cell代表列
System.out.print(sheet.getRow(row).getCell(cell) + " ");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}