有人封装了poi使其简单易用
http://git.oschina.net/jueyue/easypoi
http://git.oschina.net/jueyue/easypoi
试用了一下,很爽哦
1、引入jar
<dependency><groupId>org.jeecg</groupId><artifactId>easypoi-base</artifactId><version>2.1.3</version></dependency>
2、给持久类加入excel注解
@ExcelTarget("personInfo")public class PersonInfo extends BasePojo implements java.io.Serializable{@Excel(name = "ID", orderNum = "1")private Integer id;@Excel(name = "姓名")private String userName;@Excel(name = "身份证")private String idcard;.....................................
3、导出
//从数据库得到数据Cnd cnd = Cnd.NEW();List<PersonInfo> personInfoList = dao.query(PersonInfo.class, cnd);//文件名String codedFileName = "2015-08-18-person";//标题 sheet名//导出,两行搞定**ExportParams params = new ExportParams("考生信息", "考生信息导出");Workbook workbook = ExcelExportUtil.exportExcel(params, PersonInfo.class,personInfoList);**if (workbook instanceof HSSFWorkbook) {codedFileName += HSSF;} else {codedFileName += XSSF;}if (isIE(request)) {codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");} else {codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");}response.setHeader("content-disposition", "attachment;filename=" + codedFileName);ServletOutputStream out = response.getOutputStream();workbook.write(out);out.flush();
4、导出效果

没有评论:
发表评论