jFinal中excel导入导出

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaopingga/article/details/79496476

jFinal中excel导入导出

Jfinal刚接触不久,之前接触的java框架基本上是jeesite,所以,当接到excel导入及模板下载任务时,第一个想到的还是jeesiteApache POI 3.9的简单封装,实现Excel的导入导出功能(只适用于简单的导入导出,不合适复杂的表格或使用模板进行导入导出),

具体参考:http://blog.csdn.net/layman1024/article/details/71190927

一、实现导入导出

先将jeesite中的六个文件复制到本系统

 

而后将实体类中注入注解

 

@ExcelField(title="类型名称", align=2, sort=30)

Title是导出字段标题

Align是导出字段对齐方式(0:自动;1:靠左;2:居中;3:靠右)

Sort是导出字段排序(升序)

Controller中直接调用即可

 

 

具体代码可在码云中查找:点击打开链接

二、遇到的问题

1java.lang.IllegalStateException: Could not auto-size column. Make sure the column was tracked prior to auto-sizing the column.

 

文件下载时遇到的,原因是无法自动追踪所有的列。

解决如下:

  1.之前使用的是sheet接口,改为SXSSFSheet

  2.autoSizeColumn前使用sheet.trackAllColumnsForAutoSizing();,手动设置。

2、com.jfinal.plugin.activerecord.ActiveRecordException: The attribute name does not exist: xxx

主要是表中没有这个字段,所以在写的时候,不要写get set方法的时候,使用return get(‘xxx’)set(‘xxx’, xxx)这两个方法,而是使用return xxxthis.xxx=xxx这种,就可以解决。


另注:下载时,前台不能使用ajaxContent方法,后台返回时,可使用renderNull(),或renderFile()。

 

猜你喜欢

转载自blog.csdn.net/xiaopingga/article/details/79496476