67,512
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
try {
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File(
"F:\\(20100268号存量)测试案例.xls"));
} catch (Exception e) {
throw new Exception("file to import not found!");
}
int sheetSize = workbook.getNumberOfSheets();
Sheet sheet = null;
for (int i = 0; i < sheetSize; i++) {
sheet = workbook.getSheet(i);
}
Cell cell = null;
List list = new ArrayList();
int rowCount = sheet.getRows();
Class proj = project.class;
// 根据class对象获取属性
Field[] fields = proj.getDeclaredFields();
project proj1[] = new project[rowCount];
for (int i = 2; i < sheet.getRows(); i++) {
proj1[i] = new project();
for (int j = 0; j < sheet.getColumns(); j++) {
cell = sheet.getCell(j, i);// 获取单元格对象
String propertity = fields[j].getName().substring(0,
fields[j].getName().length());
proj1[i] = getProject(propertity, cell.getContents(),
proj1[i]); //java反射造对象
}
list.add(proj1[i]);
}
workbook.close();
System.out.println(list.size());
for (int i = 0; i < list.size(); i++) {
project p = (project) list.get(i);
System.out.println("pid=" + p.getPid());
}
} catch (Exception e) {
e.printStackTrace();
}
}
15
pid=日终网点签退统计-001
pid=
pid=
pid=日终网点签退统计-002
pid=
pid=
pid=日终网点签退统计-003
pid=
pid=
pid=日终网点签退统计-004
pid=
pid=
pid=日终网点签退统计-005
pid=
pid=