Excel和Word 简易工具类,JEasyPoi 2.1.5 版本发布
Excel和Word 簡(jiǎn)易工具類(lèi),JEasyPoi 2.1.5 版本發(fā)布?
摘要:
? ? ?jeasypoi 功能如同名字easy,主打的功能就是容易,讓一個(gè)沒(méi)見(jiàn)接觸過(guò)poi的人員 就可以方便的寫(xiě)出Excel導(dǎo)出,Excel模板導(dǎo)出,Excel導(dǎo)入,Word模板導(dǎo)出,通過(guò)簡(jiǎn)單的注解和模板 語(yǔ)言(熟悉的表達(dá)式語(yǔ)法),完成以前復(fù)雜的寫(xiě)法。
? ? 主要特點(diǎn):
? ? ? ? ? 1.設(shè)計(jì)精巧,使用簡(jiǎn)單
? ? ? ? ? 2.接口豐富,擴(kuò)展簡(jiǎn)單
? ? ? ? ? 3.默認(rèn)值多,write less do more
? ? ? ? ? 4.AbstractView 支持,web導(dǎo)出可以簡(jiǎn)單明了
一、升級(jí)日志
Excel和Word簡(jiǎn)易工具類(lèi),可以無(wú)縫集成springmvc,也為jeecg快速開(kāi)發(fā)平臺(tái)提供更便捷的,強(qiáng)大的導(dǎo)入導(dǎo)出。- 一對(duì)多表結(jié)構(gòu)導(dǎo)入導(dǎo)出BUG修正;
- jeecg 個(gè)性化定制版;
- 支持配置jeecg字典code 翻譯導(dǎo)出;
- 支持自定義字典擴(kuò)展接口,方便用戶(hù)自定義;
- 大數(shù)據(jù)導(dǎo)入導(dǎo)出優(yōu)化;
二、在線WIKI文檔
????????這幾篇是舊的教程,不過(guò)和現(xiàn)在大同小異
? ? ? ? ? ? ? ? Excel 介紹篇?Excel 工具類(lèi)?Excel 注解介紹.第一篇?Excel 注解介紹.第二篇?Excel 實(shí)體類(lèi)?Word模板導(dǎo)出教程
????????后面都是新的了
? ? ? ? ? ? ? ?JEasyPoi 在spring mvc中簡(jiǎn)易開(kāi)發(fā)方式
? ? ? ? ? ? ? ?JEasyPoi-新版自定義導(dǎo)出樣式類(lèi)型
? ? ? ? ? ? ? ?JEasyPoi-標(biāo)簽-模板導(dǎo)出的語(yǔ)法介紹
? ? ? ? ? ? ? ?JEasyPoi-Excel預(yù)覽
三、JEasyPoi?集成方法
? ? ? ? ? ?1.? ?采用 maven方式
? ? ? ? ? ? ? ? ??在pom.xml 引入以下依賴(lài)。配置私服http://maven.jeecg.org/nexus/
<dependency><groupId>org.jeecgframework</groupId><artifactId>jeasypoi-base</artifactId><version>2.1.5</version></dependency><dependency><groupId>org.jeecgframework</groupId><artifactId>jeasypoi-web</artifactId><version>2.1.5</version></dependency><dependency><groupId>org.jeecgframework</groupId><artifactId>jeasypoi-annotation</artifactId><version>2.1.5</version></dependency>2. 非maven方式
? 直接拷貝相關(guān)jar進(jìn)項(xiàng)目Lib中
四、源碼下載
? ? ? ? ? ? ? ??http://git.oschina.net/jeecg/jeasypoi
? ? ? ? ? ? ? ? ? ? ?https://github.com/zhangdaiscott/jeasypoi
五、技術(shù)交流
- ?技術(shù)論壇:www.jeecg.org
- ?QQ交流群:?⑥190866569、⑤?293658367、④176031980(滿)、②106838471(滿)
- ?在線體驗(yàn):???http://demo.jeecg.org
1.注解,導(dǎo)入導(dǎo)出都是基于注解的,實(shí)體上做上注解,標(biāo)示導(dǎo)出對(duì)象,同時(shí)可以做一些操作
@ExcelTarget("courseEntity")public class CourseEntity implements java.io.Serializable {/** 主鍵 */private String id;/** 課程名稱(chēng) */@Excel(name = "課程名稱(chēng)", orderNum = "1", needMerge = true)private String name;/** 老師主鍵 */@ExcelEntity(id = "yuwen")@ExcelVerify()private TeacherEntity teacher;/** 老師主鍵 */@ExcelEntity(id = "shuxue")private TeacherEntity shuxueteacher;@ExcelCollection(name = "選課學(xué)生", orderNum = "4")private List<StudentEntity> students;2.基礎(chǔ)導(dǎo)出 傳入導(dǎo)出參數(shù),導(dǎo)出對(duì)象,以及對(duì)象列表即可完成導(dǎo)出
HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams("2412312", "測(cè)試", "測(cè)試"), CourseEntity.class, list);3.基礎(chǔ)導(dǎo)出,帶有索引 在到處參數(shù)設(shè)置一個(gè)值,就可以在導(dǎo)出列增加索引
ExportParams params = new ExportParams("2412312", "測(cè)試", "測(cè)試");params.setAddIndex(true);HSSFWorkbook workbook = ExcelExportUtil.exportExcel(params,TeacherEntity.class, telist);4.導(dǎo)出Map 創(chuàng)建類(lèi)似注解的集合,即可完成Map的導(dǎo)出,略有麻煩
List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>();entity.add(new ExcelExportEntity("姓名", "name"));entity.add(new ExcelExportEntity("性別", "sex"));List<Map<String, String>> list = new ArrayList<Map<String, String>>();Map<String, String> map;for (int i = 0; i < 10; i++) {map = new HashMap<String, String>();map.put("name", "1" + i);map.put("sex", "2" + i);list.add(map);}HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams("測(cè)試", "測(cè)試"), entity, list);5.模板導(dǎo)出 根據(jù)模板配置,完成對(duì)應(yīng)導(dǎo)出
TemplateExportParams params = new TemplateExportParams();params.setHeadingRows(2);params.setHeadingStartRow(2);Map<String,Object> map = new HashMap<String, Object>();map.put("year", "2013");map.put("sunCourses", list.size());Map<String,Object> obj = new HashMap<String, Object>();map.put("obj", obj);obj.put("name", list.size());params.setTemplateUrl("org/jeecgframework/poi/excel/doc/exportTemp.xls");Workbook book = ExcelExportUtil.exportExcel(params, CourseEntity.class, list,map);6.導(dǎo)入 設(shè)置導(dǎo)入?yún)?shù),傳入文件或者流,即可獲得相應(yīng)的list
ImportParams params = new ImportParams();params.setTitleRows(2);params.setHeadRows(2);//params.setSheetNum(9);params.setNeedSave(true);long start = new Date().getTime();List<CourseEntity> list = ExcelImportUtil.importExcel(new File("d:/tt.xls"), CourseEntity.class, params);7.和spring mvc的無(wú)縫融合 簡(jiǎn)單幾句話,Excel導(dǎo)出搞定
@RequestMapping(params = "exportXls")public String exportXls(CourseEntity course,HttpServletRequest request,HttpServletResponse response, DataGrid dataGrid,ModelMap map) {CriteriaQuery cq = new CriteriaQuery(CourseEntity.class, dataGrid);org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, course, request.getParameterMap());List<CourseEntity> courses = this.courseService.getListByCriteriaQuery(cq,false);map.put(NormalExcelConstants.FILE_NAME,"用戶(hù)信息");map.put(NormalExcelConstants.CLASS,CourseEntity.class);map.put(NormalExcelConstants.PARAMS,new ExportParams("課程列表", "導(dǎo)出人:Jeecg","導(dǎo)出信息"));map.put(NormalExcelConstants.DATA_LIST,courses);return NormalExcelConstants.JEECG_EXCEL_VIEW;}8.Excel導(dǎo)入校驗(yàn),過(guò)濾不符合規(guī)則的數(shù)據(jù),追加錯(cuò)誤信息到Excel,提供常用的校驗(yàn)規(guī)則,已經(jīng)通用的校驗(yàn)接口
/** * Email校驗(yàn) */@Excel(name = "Email", width = 25)@ExcelVerify(isEmail = true, notNull = true)private String email;/** * 手機(jī)號(hào)校驗(yàn) */@Excel(name = "Mobile", width = 20)@ExcelVerify(isMobile = true, notNull = true)private String mobile;ExcelImportResult<ExcelVerifyEntity> result = ExcelImportUtil.importExcelVerify(new File("d:/tt.xls"), ExcelVerifyEntity.class, params);for (int i = 0; i < result.getList().size(); i++) {System.out.println(ReflectionToStringBuilder.toString(result.getList().get(i)));}9.導(dǎo)入Map 設(shè)置導(dǎo)入?yún)?shù),傳入文件或者流,即可獲得相應(yīng)的list,自定義Key,需要實(shí)現(xiàn)IExcelDataHandler接口
ImportParams params = new ImportParams();List<Map<String,Object>> list = ExcelImportUtil.importExcel(new File("d:/tt.xls"), Map.class, params);總結(jié)
以上是生活随笔為你收集整理的Excel和Word 简易工具类,JEasyPoi 2.1.5 版本发布的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: poj 1195(二维树状数组)
- 下一篇: 【发布】JEECG-P3 新主题后台风格