Excel and Word simple tools, JEasyPoi 2.1.5 version released

Excel and Word simple tools, JEasyPoi 2.1.5 version released 

Summary:

     The function of jeasypoi is just like the name easy, the main function is easy, so that a person who has never met poi can easily write Excel export, Excel template export, Excel import, Word template export, through simple annotations and template language (familiar with poi) expression syntax), to complete the previous complex writing.

    Main features:
          1. Exquisite design, easy to use
          2. Rich interface, easy to expand
          3. More default values, write less do more
          4. AbstractView support, web export can be simple and clear

 

1. Upgrade log

Excel and Word are simple tools, which can seamlessly integrate springmvc, and provide more convenient and powerful import and export for jeecg rapid development platform.

  • One-to-many table structure import and export bug fixes;
  • jeecg personalized customized version;
  • Support configuring jeecg dictionary code translation export;
  • Support custom dictionary extension interface, which is convenient for users to customize;
  • Big data import and export optimization;

2. Online WIKI documents

        These are old tutorials, but they are similar to now

                Introduction to Excel Introduction to  Excel tool class  Excel annotation. The first introduction to  Excel annotation. The second part of  Excel entity class  Word template export tutorial

        The back is new

               JEasyPoi simple development method in spring mvc

               JEasyPoi-New custom export style type

               JEasyPoi-tag-template export syntax introduction

               JEasyPoi - Excel Preview

3. JEasyPoi integration method

           1. Use maven method

                  Introduce the following dependencies in pom.xml. Configure private server 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. Non-maven way

  Copy the relevant jar directly into the project Lib

 

Four, source code download

                http://git.oschina.net/jeecg/jeasypoi

                     https://github.com/zhangdaiscott/jeasypoi

5. Technical exchange

  •  Technical Forum: www.jeecg.org
  •  QQ exchange group: ⑥190866569, ⑤ 293658367, ④176031980 (full), ②106838471 (full)
  •  Online experience:    http://demo.jeecg.org

6. Test actual combat

1. Annotation, import and export are all based on annotations. Annotations are made on the entity to indicate the export object, and some operations can be performed at the same time.

@ExcelTarget("courseEntity")
	public class CourseEntity implements java.io.Serializable {
	/** primary key */
	private String id;
	/** Course Title*/
	@Excel(name = "course name", orderNum = "1", needMerge = true)
	private String name;
	/** Teacher primary key */
	@ExcelEntity(id = "yuwen")
	@ExcelVerify()
	private TeacherEntity teacher;
	/** Teacher primary key */
	@ExcelEntity(id = "shuxue")
	private TeacherEntity shuxueteacher;

	@ExcelCollection(name = "Selected students", orderNum = "4")
	private List<StudentEntity> students;

2. Basic export Import export parameters, export objects, and object lists to complete the export

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

3. Basic export, with an index setting a value everywhere in the parameter, you can add an index to the export column

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

4. Export Map Create a collection of similar annotations to complete the export of Map, which is slightly troublesome

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

5. Template export Complete the corresponding export according to the template configuration

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. Import Set import parameters, pass in a file or stream, and you can get the corresponding 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. The seamless integration with spring mvc is a few simple words, and the Excel export is done

@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,"User Information");
        map.put(NormalExcelConstants.CLASS,CourseEntity.class);
        map.put(NormalExcelConstants.PARAMS,new ExportParams("Course List", "Exporter: Jeecg",
                "Export info"));
        map.put(NormalExcelConstants.DATA_LIST,courses);
        return NormalExcelConstants.JEECG_EXCEL_VIEW;

	}

8. Excel import verification, filter data that does not meet the rules, append error information to Excel, provide common verification rules, and have a common verification interface

/**
     * Email verification
     */
    @Excel(name = "Email", width = 25)
    @ExcelVerify(isEmail = true, notNull = true)
    private String email;
    /**
     * Mobile phone number verification
     */
    @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. Import Map Set the import parameters, pass in a file or stream, you can get the corresponding list, customize the Key, you need to implement the IExcelDataHandler interface

ImportParams params = new ImportParams();
	List<Map<String,Object>> list = ExcelImportUtil.importExcel(new File(
			"d:/tt.xls"), Map.class, params);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324389047&siteId=291194637