如何将Excel单元格值插入列表?

时间:2019-05-14 17:37:49

标签: java excel list arraylist apache-commons

所以我从Excel文件中读取数据

private static void excelRead(String fileName) throws IOException, InvalidFormatException 
{    
Workbook workbook = WorkbookFactory.create(new File(fileName));
Sheet sheet = workbook.getSheetAt(0);
DataFormatter dataFormatter = new DataFormatter();
//Loop for getting data from excel
for (Row row: sheet)
    {
        for(Cell cell: row)
        {
            String cellValue = dataFormatter.formatCellValue(cell);
        }
    }
    System.out.print("\n");
    workbook.close();
}

我无法解决如何将cellValue写入List<Student> students = new ArrayList<>();

我尝试使用diffrenets方法,但找不到方法。

Edit1:学生班

public class Student extends Person {
private Calendar startStudyYear;
private Calendar endStudyYear;

public Student(String ID, String name, String surName, academicDeggre academicDeggre, Calendar birthDay, Integer age, Sex sex, String adres, Integer prioryty, Calendar startStudyYear, Calendar endStudyYear) {
    super(ID, name, surname, academicDeggre, birthDate, age, sex, adres, prioryty);
    this.startStudyYear= startStudyYear;
    this.endStudyYear= endStudyYear;
}

1 个答案:

答案 0 :(得分:0)

我会将excel文件转换为csv。转换后,您可以选择带有FileReader的csv文件中的文本(只需将其谷歌搜索即可)。然后,您可以使用stringbuilder(只需将其谷歌搜索)将值(由特定符号分隔)分开。