easypoi导出Excel

1.参考资料
EasyPoi教程:http://easypoi.mydoc.io/#text_197817
码云地址:https://gitee.com/jeecg/easypoi

如果遇到导入导出Excel或者word,可以使用easypoi,文档中案例很齐全
一般来说我们常常会遇到报表数据的导出(Excel),下面给出一个小栗子
2.添加maven依赖

  org.jeecg
  easypoi-base
  ${easypoi.version}


  org.jeecg
  easypoi-web
  ${easypoi.version}


  org.jeecg
  easypoi-annotation
  ${easypoi.version}

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 domainList = new ArrayList();
    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)