public static void main(String[] args) throws IOException {
FileInputStream fileInput = new FileInputStream("C:\Users\DELL4\Desktop\567.xlsx");//创建文件输入流
XSSFWorkbook wb = new XSSFWorkbook(fileInput);//由输入流文件得到工作簿对象
XSSFSheet sheet = wb.getSheetAt(0);//获取第一个sheet
int lastRowNum = sheet.getLastRowNum(); //获取表格内容的最后一行的行数
//rowBegin代表要开始读取的行号,下面这个循环的作用是读取每一行内容
for (int i = 1; i <= lastRowNum; ++i) {
XSSFRow row = sheet.getRow(i);//获取每一行
int columnNum = row.getLastCellNum();//获取每一行的最后一列的列号,即总列数
for (int j = 1; j < columnNum; ++j) {
XSSFCell cell = row.getCell(j);//获取每个单元格
if (CellType.NUMERIC.equals(cell.getCellTypeEnum())) {
System.out.printf("%.0f ", cell.getNumericCellValue());
} else {
System.out.printf("%s ", cell.getStringCellValue());
}
}
System.out.println();
}
wb.close();
fileInput.close();
}