sep4j – The Simple Excel Processing for Java
通过一次静态方法调用完成 excel <=> Collection<T> 的转换
Collection<T> => Excel
Collection<User> users = Arrays.asList(user1, user2);
LinkedHashMap<String, String> headerMap = new LinkedHashMap<String, String>();
headerMap.put("userId", "User Id"); //"userId" is a property of User class.
// "User Id" will be the column header in the excel.
headerMap.put("firstName", "First Name");
headerMap.put("lastName", "Last Name");
ExcelUtils.save(headerMap, users, outputStream);
Excel => Collection<T>
Map<String, String> reverseHeaderMap = new HashMap<String,String>();
reverseHeaderMap.put("User Id", "userId"); //"User Id" is a column header in the excel.
//"userId" is the corresponding property of User class.
reverseHeaderMap.put("First Name", "firstName");
reverseHeaderMap.put("Last Name","lastName");
List<User> users = ExcelUtils.parseIgnoringErrors(reverseHeaderMap, inputStream, User.class);
以上是两个最简单的例子。sep4j另有错误处理、相异类型转换的功能,请移步官方主页:
https://github.com/chenjianjx/sep4j