EasyExcel導出簡單使用


github地址:https://github.com/alibaba/easyexcel;

參考網址:https://alibaba-easyexcel.github.io/index.html

引入jar:

<!-- 阿里巴巴 easyExcel依賴 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.6</version>
</dependency>



頁面請求:<a href="/easyExcelUtil/getExportData" target="_blank">EasyExcel導出測試</a>

/**
     * 頁面導出
     * @param
     */
    @GetMapping(value = "/daochuStatisticToExcel")
    @ResponseBody
    public Object daochuStatisticToExcel(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            
            List list = getDataList();

            String fileName = new String("文件名稱.xlsx".getBytes(), "ISO-8859-1");
            response.addHeader("Content-Disposition", "filename=" + fileName);
            ServletOutputStream out = response.getOutputStream();
            EasyExcelFactory.write(out,ExcelData.class).sheet("文件標簽名稱").doWrite(list);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.toString(), e);
        }
        return null;
    }
@Data
public class SwitchStatisticData  extends BaseRowModel {

    @ExcelProperty({"總標題", "日期標題"})
    private Date tDate;//日期
    @ExcelProperty({"總標題", "數量"})
    private Long countNum;//數量
    @ExcelProperty({"總標題", "內容"})
    private String count;//內容
}

 


免責聲明!

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



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