excel 模版:
输出结果
java 代码片段:
private static void test01(String name) throws IOException {
try (InputStream in = new FileInputStream(new File(String.format(gen, name)));
OutputStream out = new FileOutputStream(new File(String.format(gen, System.currentTimeMillis() + name + "out")))) {
List<User> data = new User().mock();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("excelModelList", data);
dataMap.put("excelModelList2", data);
JxlsHelper jxlsHelper = JxlsHelper.getInstance();
jxlsHelper.getAreaBuilder().getTransformer();
//设置自适应行高
//XlsCommentAreaBuilder.addCommandMapping("autoRowHeight", AutoRowHeightCommand.class);
jxlsHelper.setUseFastFormulaProcessor(false);
jxlsHelper.processTemplate(in, out, new Context(dataMap));
in.close();
out.close();
}
user
public class User {
private Integer age;
private String name;
private Integer sex;
public List<User> mock() {
List<User> list = new ArrayList<>();
for (int i = 1; i < 20; i++) {
list.add(new User(i, "zyy", 1));
}
return list;
}
public User() {
}
public User(Integer age, String name, Integer sex) {
this.age = age;
this.name = name;
this.sex = sex;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
}
问题待解决~