easypoi封裝了poi讓咱們可以很是簡單的實現Excel導出,Excel模板導出,Excel導入,Word模板導出等,具體可見官網:http://www.afterturn.cn/
spring
我這邊實現了一個excel的導出,記錄一下。sql
<dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-spring-boot-starter</artifactId> <version>3.2.0</version> </dependency>
@Table(name = "ORDERS") public class OrderExcelDto{ @Excel(name = "ORDER_ID", width = 25,orderNum = "0") private String orderId; @Excel(name = "CREATE_TIME",width = 20,exportFormat = "yyyy-MM-dd HH:mm:ss", orderNum = "1") private Date createTime; @Excel(name = "STATUS",width = 20,replace = {"created_01", "payment_02","used_03","time out_04"}, orderNum = "2") private String status; public String getOrderId() { return orderId; } public void setOrderId(String orderId) { this.orderId = orderId; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } }
具體語義以下,詳情可見官網
name:列明;replace:前者是最後替換的值,後者是數據庫的值;exportFormat:導出的時間格式,以這個是否爲空來判斷是否須要格式化日期;width:列寬等
@GetMapping("/orderExport") public void orderExport(HttpServletResponse response) throws Exception { response.setHeader("content-Type", "application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=orders.xls"); List<OrderExcelDto> list = orderService.queryOrderExcel(); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(),OrderExcelDto.class,list); workbook.write(response.getOutputStream()); }
function export() { document.location.href = host+"/orderExport"; }
就這樣就能夠很是快速的實現一個excel導出了,還有不少好用的功能能夠看官網。數據庫