easyexcel 简单填充

x33g5p2x  于2021-12-28 转载在 其他  
字(1.2k)|赞(0)|评价(0)|浏览(802)

easyexcel 简单填充

********************

示例

Test

@Data
class Product{

    private Integer id;
    private String name;
    private Double price;
    private String desc;
}

public class Test {

    private static final String template_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"template.xlsx";
    private static final String fill_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"fill.xlsx";
    private static final String fill_path2="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"fill2.xlsx";

    public static void fill(){
        Product product=new Product();
        product.setId(1);
        product.setName("apple");
        product.setPrice(10d);

        EasyExcel.write(fill_path,Product.class).withTemplate(template_path).sheet().doFill(product);
    }

    public static void fill2(){
        Map<String,Object> map=new HashMap<>();
        map.put("id",1);
        map.put("name","banana");
        map.put("price",6);

        EasyExcel.write(fill_path2).withTemplate(template_path).sheet().doFill(map);
    }

    public static void main(String[] args){
        fill();
        fill2();
    }
}

使用测试

填充模板

                     

fill

                     

fill2

                     

相关文章