EasyPOI是在jeecg的poi模塊基礎上,繼續開發獨立出來的,能夠說是2.0版本,EasyPoi封裝的目的和jeecg一致,爭取讓你們write less do more ,在這個思路上easypoi可讓你們幾乎不寫代碼的狀況下完成Excel的導入導出,Excel的模板導出(製做漂亮的Excel),Word模板的導出,讓你們從複雜的POI的接口中解脫出來,同時更迅速的完成工做.web
EasyPoi的特性spring
• 註解是基礎,讓你們見名知意瀏覽器
• 註解是核心,讓你們快速開發spring-mvc
• 簡單的導出導入接口,能夠快速完成mvc
• 簡單的數據接口,自定義數據app
• Excel模板,美化的Excel,程序一天,Excel1分鐘less
• Word模板,通知類文件的強大神器maven
• SpringView集成工具
easypoi在項目中的應用:編碼
須要引入的jar包:
<!--easypoi導出excel--> <!--easypoi-base 導入導出的工具包,能夠完成Excel導出,導入,Word的導出,Excel的導出功能--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-base</artifactId> <version>2.3.1</version> </dependency> <!--easypoi-web 耦合了spring-mvc 基於AbstractView,極大的簡化spring-mvc下的導出功能--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-web</artifactId> <version>2.3.1</version> </dependency> <!--easypoi-annotation 基礎註解包,做用與實體對象上,拆分後方便maven多工程的依賴管理--> <dependency> <groupId>org.jeecg</groupId> <artifactId>easypoi-annotation</artifactId> <version>2.3.1</version> </dependency>
而後在實體類中添加easypoi的註解:
@ExcelTarget("summaryexcel") @Data public class SummaryExcel { @Excel(name = "日期", orderNum = "1", mergeVertical = true, isImportField = "date") private String date;//當天日期 @Excel(name = "能源類型", orderNum = "2", mergeVertical = true, isImportField = "type") private String type; // 能源類型 @Excel(name = "能源用量", orderNum = "3", mergeVertical = true, isImportField = "sum") private Double sum; // 用量 }
而後就能夠在controller層直接使用easypoi:
@GetMapping("getexcel")
public void download(HttpServletRequest request, HttpServletResponse response,String start,String end) throws Exception { // 告訴瀏覽器用什麼軟件能夠打開此文件 response.setHeader("content-Type", "application/vnd.ms-excel"); // 下載文件的默認名稱 response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("數據表","UTF-8") + ".xls"); //編碼 response.setCharacterEncoding("UTF-8"); List<SummaryExcel> list = summaryService.summaryexcel(start,end); Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), SummaryExcel.class, list); workbook.write(response.getOutputStream()); }
這樣一個簡單的用easypoi實現excel導出就完成了。
easypoi在開源中國:https://www.oschina.net/news/54995/jeecg-easypoi-2-0-3
easypoi文檔:http://easypoi.mydoc.io/