easypoi入門<1


學習自: http://www.afterturn.cn/doc/easypoi.html

開源地址: https://gitee.com/lemur/easypoi

https://gitee.com/lemur/easypoi-spring-boot-starter

maven項目,加入依賴

<dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>3.2.0</version>
        </dependency>
View Code

需要導出的數據實體加上注解

/**
     * 名字
     */
    @Excel(name="名字")
    private String name;
    /**
     * 生日
     */
    @Excel(name="生日",format="yyyy-MM-dd",databaseFormat="yyyyMMddHHmmss")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;
    /**
     * 性別(1:男 2:女)
     */
    @Excel(name="性別",replace= {"男_1","女_2"},suffix="生")
    private Integer sex;
    /**
     * 電子郵件
     */
    @Excel(name="電子郵件")
    private String email;
    /**
     * 電話
     */
    @Excel(name="電話")
    private String phone;
@RequestMapping("/loadExcel")
    public void downloadByPoiBaseView(ModelMap map, HttpServletRequest request,
            HttpServletResponse response) {
        //這個要考慮offic Excel 是2007還是2003.2007可以導百萬數據; 2003只能導6萬超過的是空白,數據量特別大建議分sheet導或者分條件導
        List<User> list = userService.excelList(null);//查詢數據庫數據
        //List<User> list = new ArrayList<>();
        //new ExportParams(String title,String sheet,String suffix);分別是表頭,頁名稱,文件類型
        ExportParams params = new ExportParams("用戶信息","用戶信息",ExcelType.XSSF);
        params.setFreezeCol(10);//凍結列(分割線/無論有多少列,拖動左右滾動條一直顯示的列.)
        params.setStyle(ExcelExportStylerColorImpl.class);//設置樣式,自定義實現IExcelDataHandler<T>
        map.put(NormalExcelConstants.DATA_LIST, list);//數據
        map.put(NormalExcelConstants.CLASS, User.class);//類型
        map.put(NormalExcelConstants.PARAMS, params);//excel參數
        map.put(NormalExcelConstants.FILE_NAME, "用戶信息");
        
        PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);//無返回值下載
    }

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM