自己封装的excel导出/导入,可以根据注解来导出excel.本项目一共有13个类,里面还包含了一个反射工具,一个编码工具,10分值了。下面是测试代码
public class Test {
public static void main(String[] arg) throws FileNotFoundException, IOException{
testBean();
testMap();
}
public static void testBean() throws FileNotFoundException, IOException{
List l = new ArrayList();
for(int i=0;i<100;i++){
l.add(new MyBean());
}
//很轻松,只需要二句话就能导出excel
BeanExport be = ExportExcel.BeanExport(MyBean.class);
be.createBeanSheet("1月份", "1月份人员信息").addData(l);
be.createBeanSheet("2月份","2月份人员信息").addData(l);
be.writeFile("E:/test/bean人员信息8.xlsx");
}
//如果不想用注解,还能根据MAP导出.
public static void testMap () throws FileNotFoundException, IOException{
List l = new ArrayList();
l.add(new MapHeader("姓名","name",5000));
l.add(new MapHeader("年龄","age",4000));
l.add(new MapHeader("生日","birthdate",3000));
l.add(new MapHeader("地址","address",5000));
l.add(new MapHeader("双精度","d",4000));
l.add(new MapHeader("float","f",6000));
List<Map> lm = new ArrayList<Map>();
for(int i=0;i<100;i++){
Map map = new HashMap();
map.put("name","闪电球");
map.put("age",100);
map.put("birthdate",new Date());
map.put("address","北京市广东省AAA号123楼!");
map.put("d",22.222d);
map.put("f",295.22f);
lm.add(map);
}
MapExport me = ExportExcel.mapExport(l);
me.createMapSheel("1月份","广东省人员信息").addData(lm);
me.createMapSheel("2月份", "北京市人员信息").addData(lm);
me.writeFile("E:/test/map人员信息9.xlsx");
}
}