简体   繁体   English

如何将 Excel 文件读入列表<Map<String, String> &gt;

[英]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.

相关问题 读取文件并映射到地图 <String, List<String> &gt; - Read a file and map to a Map<String, List<String>> Java - 如何将 CSV 文件读入 Map <string, map<string, string> ></string,> - Java - How to read a CSV file into a Map<String, Map<String, String>> 如何转换 Map<string ,list> 至 Map <string , map<> &gt; 使用 Java 8</string></string> - How can I convert Map<String ,List > to Map<String , Map<>> using Java 8 如何将 Excel 单元格中的数字字符串读取为字符串(而非数字)? - How can I read numeric strings in Excel cells as string (not numbers)? 如何转换 map 列表的列表<map<string, string> &gt; myList 到 Java 中的 Spark Dataframe? </map<string,> - How can I convert a list of map List<Map<String, String>> myList to Spark Dataframe in Java? 如何从Map中获取值 <String List<Object> &gt; - How can I get the values from Map<String List<Object>> 如何对 Map 进行排序<string, list<customobject> &gt;?</string,> - How can I sort a Map<String, List<CustomObject>>? 我可以转换地图吗<String, List<Integer> &gt; 进入 MultiValueMap<String, Integer> - Can I convert a Map<String, List<Integer>> into a MultiValueMap<String, Integer> 如何使用String List编写Excel文件 - How to write Excel file by using String List 如何创建 Map <string, list<string> &gt; 可以使用 Spring 的 @Value 注入的属性文件中的属性</string,> - How to create a Map<String, List<String>> property in properties file that can be injectable using Spring's @Value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM