POI 注解方式 导入导出 excel , 只依赖于 POI包
来源:互联网 发布:nginx如何反向代理 编辑:程序博客网 时间:2024/05/17 00:06
package cn.com.guangduo.zjyxcg.common.util;import java.util.Date;import cn.com.guangduo.zjyxcg.common.util.excel.annotation.AnnExcelColumn;import cn.com.guangduo.zjyxcg.common.util.excel.annotation.AnnExcelSheet;@AnnExcelSheet(name="生产企业信息")public class ExcelImportAndExportBean {@AnnExcelColumn(title="企业名称",width=-1)private String name;@AnnExcelColumn(title="注册资金(万元)",format="0.00",order=2)private Double capital;@AnnExcelColumn(title="传真",order=4)private String fax;@AnnExcelColumn(title="起始日期",format="yyyy年MM月dd日",width=200)private Date startDate;@AnnExcelColumn(title="年检年度",format="#年")private Integer year;public String getName() {return name;}public void setName(String name) {this.name = name;}public Double getCapital() {return capital;}public void setCapital(Double capital) {this.capital = capital;}public String getFax() {return fax;}public void setFax(String fax) {this.fax = fax;}public Date getStartDate() {return startDate;}public void setStartDate(Date startDate) {this.startDate = startDate;}public Integer getYear() {return year;}public void setYear(Integer year) {this.year = year;}@Overridepublic String toString() {return "ExcelImportAndExportBean [name=" + name + ", capital="+ capital + ", fax=" + fax + ", startDate=" + startDate+ ", year=" + year + "]";}}
package cn.com.guangduo.zjyxcg.common.util;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.OutputStream;import java.util.List;import cn.com.guangduo.zjyxcg.common.util.excel.ExcelUtil;import cn.com.guangduo.zjyxcg.common.util.excel.bean.IExcelExport;import cn.com.guangduo.zjyxcg.common.util.excel.bean.IExcelImport;public class ExcelImportAndExportTest {//么有junitvoid testImport(){IExcelImport imp = ExcelUtil.getImport();}public static void main(String[] args) throws Exception {//获取导入实例IExcelImport imp = ExcelUtil.getImport();//传入输入流 以及 注解了的bean对象 返回 对象数组List<ExcelImportAndExportBean> beans = imp.execute(new FileInputStream("E:/生产企业.xlsx"), ExcelImportAndExportBean.class);System.out.println("==========================================");for (ExcelImportAndExportBean bean : beans) {System.out.println(bean);}System.out.println("==========================================");//获取导出实例IExcelExport exp = ExcelUtil.getExport();//传入输入流, 数据, 以及 注解的 bean 对象//扩展名是xls,为了兼容,输出 1997~2013 格式的文档//起始可以根据 beans 的 类型确认 第三个参数的class,但是没找到获取的方法OutputStream os = new FileOutputStream("E:/导出的数据.xls");exp.execute(os, beans, ExcelImportAndExportBean.class);exp.setTitleStyel(null);//设置标题样式System.out.println("==========================================");}}
package cn.com.guangduo.zjyxcg.common.util.excel.annotation;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import cn.com.guangduo.zjyxcg.common.enums.ICommonEnum;import cn.com.guangduo.zjyxcg.common.util.excel.enums.ExcelColumnType;/** * 导入导出字段的注解 * * @author zhang.xiaolei * @createDate 2015年5月27日 */@Target(ElementType.FIELD)@Retention(RetentionPolicy.RUNTIME)public @interface AnnExcelColumn {/** * Excel 标题名称 */String title(); /** * 输出的的格式 */String format() default ""; /** * 在什么时间处理,导入, 导出, 全部 */ExcelColumnType type() default ExcelColumnType.ALL; /** * 导出时标题的顺序 由小到大 */int order() default 0;/** * 导入时候的简单验证 * FIXME 以后再处理 */String validate() default "";/** * 枚举类型的相互转换,必须是 ICommonEnum 的实现 * FIXME 暂未实现 */Class<ICommonEnum> enumType() default ICommonEnum.class;/** * 列宽,<br/>0 默认值,为不处理, * <br/>-1 自动宽度, * <br/> 其他值 就会设置为宽度 * * @default 0 */int width() default 0;}
哈哈, 直接上代码,实在人,具体内容见附件。
功能还没有完胜,用起来基本没有问题,可能有些类型转换问题, 遇到的加上就好了!
String,Double,Date , Integer 这几种类型毫无问题!
0 0
- POI 注解方式 导入导出 excel , 只依赖于 POI包
- excel导入导出使用poi自定义注解
- excel 导入导出使用poi自定义注解
- poi导入导出excel
- poi excel导入导出
- POI导入/导出 EXCEL
- POI Excel导入导出
- poi excel导入导出
- POI导入导出excel
- poi导入导出excel
- poi导入导出excel
- poi 方式导出excel
- Java SSM注解实现POI导入导出Excel
- 使用POI导入,导出Excel
- java excel poi 导入导出
- poi操作excel导入\导出
- poi导入导出excel后记
- POI Excel 导入导出数据库
- UserInfoService
- 第十三周阅读项目(5):链表类
- 唐山治自闭症哪里最好
- eclipse代码软件自动生成uml类图
- 菜鸟学Android(八):dom4j的增删改查
- POI 注解方式 导入导出 excel , 只依赖于 POI包
- AndroidManifest.xml配置文件详解
- 7种经典排序算法的图解
- win8.1 64位qt5.4.0 gui程序调用控制台窗口
- TT日程管理V2.0开发系列1——经验分享
- hdu 3496 Watch The Movie(二维01背包)
- 31.modal方式弹出控制器的view
- xcode 运行错误总结
- WebRequest.GetSystemWebProxy()的效能问题