richFaces 4,3,2 rich:fileUpload
上传页面:
uploadListener方法:
public void uploadListener(FileUploadEvent event) {
UploadedFile item = event.getUploadedFile();
List<DirExpBudget> tmpList = new ArrayList<DirExpBudget>();
setListDirExpBudget(new ArrayList<DirExpBudget>());
try {
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(item.getInputStream());
} catch (BiffException e) {
procException(e, "得到Excel");
return;
} catch (
IOException e) {
procException(e, "得到Excel");
return;
}
Sheet[] sheets = workbook.getSheets(); // 获取所有sheet页
for (int n = 0; n < sheets.length; n++) {
Sheet sheet = sheets[n];
int row = sheet.getRows(); // 获取信息总行数
if (sheet.getCell(0, 1).getContents().split(":").length <= 1) {
setAlertMessage("第" + (n + 1) + "个sheet页,部门名称不存在,请检查!");
return;
}
String bmmc = sheet.getCell(0, 1).getContents().split(":")[1]
.trim(); // 获取部门名称
String conditionDept = " entity.deptName = '" + bmmc
+ "' AND entity.deptType = '01'";
if (sheet.getCell(6, 1).getContents().split(":").length <= 1) {
setAlertMessage("第" + (n + 1) + "个sheet页,科目名称不存在,请检查!");
return;
}
.......
for (int j = 5; j < row; j++) { // j 行
dirExpBudget = new DirExpBudget();
......
tmpList.add(dirExpBudget);
}
}
} catch (
NumberFormatException e) {
procException(e, "导入");
return;
}
&nbs