1 Unstar Star 0 Fork 2K

突然空闲 / easypoiApache-2.0

forked from Lemur开源 / easypoi 
Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
POI 工具类,Excel的快速导入导出,Excel模板导出,Word模板导出,可以仅仅5行代码就可以完成Excel的导入导出,修改导出格式简单粗暴,快速有效,easypoi值得你尝试 spread retract

Clone or download
jueyue authored update
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

=========================== EasyPoi Excel和 Word简易工具类

easypoi功能如同名字easy,主打的功能就是易容,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言(熟悉的表达式语法),完成以前复杂的写法

作者博客:http://blog.csdn.net/qjueyue
作者邮箱: qrb.jueyue@gmail.com

EasyPoi的主要特点

1.设计精巧,使用简单
2.接口丰富,扩展简单
3.默认值多,write less do more
4.AbstractView 支持,web导出可以简单明了

EasyPoi的几个入口工具类

1.ExcelExportUtil Excel导出(普通导出,模板导出)
2.ExcelImportUtil Excel导入
3.WordExportUtil Word导出(只支持docx ,doc版本poi存在图片的bug,暂不支持)

版本修改

  • 2.0.6-release

    • 修复导入的自定义格式异常
    • 修复导入的BigDecimal不识别
    • 导出大数据替换为SXSSFWorkbook,提高07版本Excel导出效率
    • 根据sonar的提示,修复编码格式问题
    • 做了更加丰富的测试
    • word 导出的优化
  • 2.0.6-SNAPSHOT

    • 增加map的导出
    • 增加index 列

EasyPoi导出实例

1.注解,导入导出都是基于注解的,实体上做上注解,标示导出对象,同时可以做一些操作

	@ExcelTarget("courseEntity")
	public class CourseEntity implements java.io.Serializable {
	/** 主键 */
	private String id;
	/** 课程名称 */
	@Excel(name = "课程名称", orderNum = "1", needMerge = true)
	private String name;
	/** 老师主键 */
	@ExcelEntity(id = "yuwen")
	@ExcelVerify()
	private TeacherEntity teacher;
	/** 老师主键 */
	@ExcelEntity(id = "shuxue")
	private TeacherEntity shuxueteacher;

	@ExcelCollection(name = "选课学生", orderNum = "4")
	private List<StudentEntity> students;

2.基础导出 传入导出参数,导出对象,以及对象列表即可完成导出

	HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams(
				"2412312", "测试", "测试"), CourseEntity.class, list);

3.基础导出,带有索引 在到处参数设置一个值,就可以在导出列增加索引

	ExportParams params = new ExportParams("2412312", "测试", "测试");
	params.setAddIndex(true);
	HSSFWorkbook workbook = ExcelExportUtil.exportExcel(params,
			TeacherEntity.class, telist);

4.导出Map 创建类似注解的集合,即可完成Map的导出,略有麻烦

	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(
			"测试", "测试"), entity, list);	

5.模板导出 根据模板配置,完成对应导出

	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.导入 设置导入参数,传入文件或者流,即可获得相应的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的无缝融合 简单几句话,Excel导出搞定

	@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,"用户信息");
        map.put(NormalExcelConstants.CLASS,CourseEntity.class);
        map.put(NormalExcelConstants.PARAMS,new ExportParams("课程列表", "导出人:Jeecg",
                "导出信息"));
        map.put(NormalExcelConstants.DATA_LIST,courses);
        return NormalExcelConstants.JEECG_EXCEL_VIEW;

	}

Comments ( 0 )

Sign in for post a comment

1
https://gitee.com/steed_ns/easypoi.git
git@gitee.com:steed_ns/easypoi.git
steed_ns
easypoi
easypoi
master

Search

132457 8cb2edc1 1899542 131848 70c8d3a4 1899542