Java操作excel框架
Java Excel俗稱jxl,可以讀取Excel文件的內容、創建新的Excel文件、更新已經存在的Excel文件,現在基本沒有更新了
Apache POI是Apache基金組織Jakarta項目的子項目,它包括一系列的API,可以操作多種格式的Microsoft Office文件,通過這些API使Java更方便的操作Excel、Word等格式的Office文件
EasyPoi功能如同名字easy,主打的功能就是容易,讓一個沒見接觸過poi的人員 就可以方便的寫出Excel導出,Excel模板導出,Excel導入,Word模板導出,通過簡單的注解和模板 語言(熟悉的表達式語法),完成以前復雜的寫法
最終下載效果

項目圖片

UserController.download方法
- 簡單的飛起
// 下載execl文檔
@RequestMapping("/download")
public void download(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 告訴瀏覽器用什么軟件可以打開此文件
response.setHeader("content-Type", "application/vnd.ms-excel");
// 下載文件的默認名稱
response.setHeader("Content-Disposition", "attachment;filename=user.xls");
List<User> list = userRepository.findAll();
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), User.class, list);
workbook.write(response.getOutputStream());
}
User.java
@Entity
@Table(name = "t_user")
@ExcelTarget("user")
public class User {
@Id
@GeneratedValue
@Excel(name = "編號", orderNum = "1", mergeVertical = true, isImportField = "id")
private Long id;
@Excel(name = "姓名", orderNum = "2", mergeVertical = true, isImportField = "name")
private String name;
@Excel(name = "年齡", orderNum = "3", mergeVertical = true, isImportField = "age")
private Integer age;
其他關聯項目
- Spring Boot 系列教程7-EasyUI-datagrid
http://blog.csdn.net/je_ge/article/details/53365189
源碼地址
https://github.com/je-ge/spring-boot
如果覺得我的文章對您有幫助,請予以打賞。您的支持將鼓勵我繼續創作!謝謝!

