为什么不能输出所有数据?package com.demon.util; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import com.demon.bean.Book; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; import jxl.write.WriteException; public class ExcelUtil { public static void excelOut(ArrayList ar, String str) { WritableWorkbook book = null; try { book = Workbook.createWorkbook(new File(str)); WritableSheet sheet = book.createSheet("sheet", 0); for (int i = 0; i < ar.size(); i++) { Object ob = ar.get(i); Class cl = ob.getClass(); Field[] fi = cl.getDeclaredFields(); for (int j = 0; j < fi.length; j++) { fi[j].setAccessible(true); Label la = new Label(j, i, String.valueOf(fi[j].get(ob))); sheet.addCell(la); } book.write(); } } catch (Exception e) { // TODO: handle exception } finally { try { book.close(); } catch (WriteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public static void main(String[] args) { ArrayList<Book> ar=new ArrayList<Book>(); Book bo=new Book(); bo.setId(1); bo.setName("月子"); bo.setType("生活"); Book bo2=new Book(); bo2.setId(2); bo2.setName("日子"); bo2.setType("生活"); ar.add(bo); ar.add(bo2); ExcelUtil.excelOut(ar, "/Users/piepie/Desktop/boos.xls"); } }
添加回答
举报
0/150
提交
取消