try {
//创建工作簿对象
XSSFWorkbook xssfWorkbook = null;
xssfWorkbook = new XSSFWorkbook(new FileInputStream("/Users/xinhuazhiyun/Desktop/经销商对应的大区.xlsx"));
Map<String,String> result = new HashMap<>();
//获取工作簿下sheet的个数
int sheetNum = xssfWorkbook.getNumberOfSheets();
System.out.println("该excel文件中总共有:" + sheetNum + "个sheet");
//遍历工作簿中的所有数据
for (int i = 0; i < sheetNum; i++) {
//读取第i个工作表
System.out.println("读取第" + (i + 1) + "个sheet");
XSSFSheet sheet = xssfWorkbook.getSheetAt(i);
//获取最后一行的num,即总行数。此处从0开始
int maxRow = sheet.getLastRowNum();
for (int row = 0; row <= maxRow; row++) {
//获取最后单元格num,即总单元格数 ***注意:此处从1开始计数***
int maxRol = sheet.getRow(row).getLastCellNum();
System.out.println("--------第" + row + "行的数据如下--------");
for (int rol = 0; rol < maxRol; rol++) {
System.out.print(sheet.getRow(row).getCell(rol) + " ");
}
System.out.println();
}
}
} catch (Exception e) {
e.printStackTrace();
}
简单读取Excel表
最新推荐文章于 2024-11-01 14:48:20 发布