美文网首页
easypoi导出Excel

easypoi导出Excel

作者: jsjack_wang | 来源:发表于2018-01-10 21:24 被阅读0次
    1.参考资料
    EasyPoi教程:http://easypoi.mydoc.io/#text_197817
    码云地址:https://gitee.com/jeecg/easypoi
    
    如果遇到导入导出Excel或者word,可以使用easypoi,文档中案例很齐全
    一般来说我们常常会遇到报表数据的导出(Excel),下面给出一个小栗子
    
    2.添加maven依赖
    <dependency>
      <groupId>org.jeecg</groupId>
      <artifactId>easypoi-base</artifactId>
      <version>${easypoi.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jeecg</groupId>
      <artifactId>easypoi-web</artifactId>
      <version>${easypoi.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jeecg</groupId>
      <artifactId>easypoi-annotation</artifactId>
      <version>${easypoi.version}</version>
    </dependency>
    
    3.Java导出Excel
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;
    import lombok.ToString;
    import org.jeecgframework.poi.excel.annotation.Excel;
    import org.jeecgframework.poi.excel.annotation.ExcelTarget; 
    import java.io.Serializable;
    
    @Data
    @ExcelTarget("courseDomain")
    @NoArgsConstructor
    @AllArgsConstructor
    @ToString
    public class CourseDomain implements Serializable {
    
        @Excel(name = "课程名称", width = 25)
        private String name;
    
        @Excel(name = "教师名称", width = 25)
        private String teacherName;
    
        @Excel(name = "学生数量", width = 10)
        private int studentNumber;
    
        @Excel(name = "描述", width = 40)
        private String desc;
    }   
    
    public static void main(String[] args) throws Exception {
        List<CourseDomain> domainList = new ArrayList<CourseDomain>();
        domainList.add(new CourseDomain("语文", "tom", 33, "很有趣"));
        domainList.add(new CourseDomain("数学", "jack", 13, "可能有点难"));
        domainList.add(new CourseDomain("C++", "jackson", 133, "我们很有兴趣"));
    
        ExportParams params = new ExportParams("课程详情", null, "课程详情");
        Workbook workbook = ExcelExportUtil.exportExcel(params, CourseDomain.class, domainList);
        File targetFile = new File("temp.xls");
        FileOutputStream fos = new FileOutputStream(targetFile);
        workbook.write(fos);
        fos.close();
    }
    
    5.SpringMVC无缝融合 Excel导出可以参考文档 有具体实例

    源码地址:https://gitee.com/jsjack_wang/JavaDemo

    相关文章

      网友评论

          本文标题:easypoi导出Excel

          本文链接:https://www.haomeiwen.com/subject/dpjanxtx.html