How can I read Excel file into List<Map<String, String>>

902 Views Asked by At

How can I read excel file into List<Map<String, String>>, where first I need to get column names from excel, then to get all values and put it into List<Map<String, String>>. I want to get a some value from this collection like this: String columnValue = map.get("column_name");

1

There are 1 best solutions below

1
On

You can export the data from excel in CSV format and use Apache's CSV parser library for JAVA.

And then after importing the library in your classpath you can simply use it as

Reader in = new FileReader("path/to/file.csv");
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in);
for (CSVRecord record : records) {
    String lastName = record.get("Last Name");
    String firstName = record.get("First Name");

}

After this you can store data in your List in desired way.

For more information look into https://commons.apache.org/proper/commons-csv/index.html