文章18 | 阅读 21378 | 点赞0
示例
header 类
Product
@Data
public class Product {
private Integer id;
private String productName;
private Double price;
@ExcelIgnore
private String desc;
}
Product2
@Data
public class Product2 {
private Integer id;
private String productName;
private Double price;
private String desc;
}
测试类
Test
public class Test4 {
private static final String file_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"write_test8.xlsx";
private static List<Product> data(){
List<Product> list=new ArrayList<>();
for (int i=0;i<5;i++){
Product product=new Product();
product.setId(i);
product.setProductName("海贼王"+i);
product.setPrice((double)(i+10));
product.setDesc("动漫");
list.add(product);
}
return list;
}
public static void main(String[] args){
ExcelWriter excelWriter=null;
Set<String> excludeColumns=new HashSet<>();
excludeColumns.add("id");
try {
excelWriter=EasyExcel.write(file_path).build();
WriteSheet writeSheet=EasyExcel.writerSheet(0,"sheet").head(Product.class).build();
WriteSheet writeSheet2=EasyExcel.writerSheet(1,"sheet2").head(Product2.class)
.excludeColumnFiledNames(excludeColumns).build();
excelWriter.write(data(),writeSheet);
excelWriter.write(data(),writeSheet2);
}finally {
if (excelWriter!=null){
excelWriter.finish();
}
}
}
}
使用测试
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/weixin_43931625/article/details/107580864
内容来源于网络,如有侵权,请联系作者删除!