package com.hsbc.dashboard.utils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class FileParseExcel {
    public static final String file_path = "D:\\SpringWeb\\src\\test\\resources\\UserProfiles\\user.xlsx";
    @Test
    public void readUserExcel() throws IOException {
        File file = new File(file_path);
        FileInputStream fis = new FileInputStream(file);
        Workbook workbook = new XSSFWorkbook(fis);
        Sheet sheet = workbook.getSheet("userinformation");
        int lastRowNum = sheet.getLastRowNum();
        Cell userCell;
        for(int i = 1; i <= lastRowNum; i++){
            Map<String, String> userData = new HashMap<>();
            Row row = sheet.getRow(i);
            userCell = row.getCell(1);  //获取单元格
            userCell.setCellType(CellType.STRING);  //设置单元格类型
            String dd = userCell.getStringCellValue();  //获取单元格数据
            userData.put("age", dd);
            System.out.println(userData);
        }
    }
}
{age=20}
{age=21}
{age=25}
{age=22}
原文:https://www.cnblogs.com/meiyouyou/p/14672648.html