[英]How can I read Excel file into List<Map<String, String>>
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>>
.如何将 excel 文件读入
List<Map<String, String>>
,首先我需要从 excel 获取列名,然后获取所有值并将其放入List<Map<String, String>>
。 I want to get a some value from this collection like this: String columnValue = map.get("column_name");
我想从这个集合中得到一个这样的值:
String columnValue = map.get("column_name");
You can export the data from excel in CSV format and use Apache's CSV parser library for JAVA.您可以将 Excel 中的数据以 CSV 格式导出,并使用 Apache 的 JAVA CSV 解析器库。
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有关更多信息,请查看https://commons.apache.org/proper/commons-csv/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.