|
|
|
@ -152,11 +152,11 @@ public class ExcelOperation {
|
|
|
|
|
* @throws InstantiationException
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
*/
|
|
|
|
|
public static List readExcel4Update(XSSFWorkbook workbook, int excelInitRow, int excelInitCell, Object obj, String... filter) throws InstantiationException, IllegalAccessException {
|
|
|
|
|
public static List readExcel4Update(XSSFWorkbook workbook, int excelInitRow, int excelInitCell, String fileName, List<String> rowErr, Object obj, String... filter) throws InstantiationException, IllegalAccessException {
|
|
|
|
|
List<String> filters = new ArrayList<String>();
|
|
|
|
|
Class<?> classz = obj.getClass();
|
|
|
|
|
filters.addAll(Arrays.asList(filter));
|
|
|
|
|
List list = null;
|
|
|
|
|
List list = new ArrayList<Object>();;
|
|
|
|
|
//读取工作表
|
|
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0);//getSheet("Sheet1");
|
|
|
|
|
XSSFRow row;
|
|
|
|
@ -176,7 +176,7 @@ public class ExcelOperation {
|
|
|
|
|
//获得当前行
|
|
|
|
|
row = sheet.getRow(i);
|
|
|
|
|
cell = row.getCell(excelInitCell);
|
|
|
|
|
if ("-".equals(getValue(cell))) {
|
|
|
|
|
if ("-".equals(getValue(cell)) || "".equals(getValue(cell))) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//实例化
|
|
|
|
@ -203,6 +203,7 @@ public class ExcelOperation {
|
|
|
|
|
isAddObj = true;
|
|
|
|
|
String type = tmpField.getGenericType().toString();
|
|
|
|
|
//int型
|
|
|
|
|
try{
|
|
|
|
|
if (type.contains("Integer") ||type.contains("int")) {
|
|
|
|
|
double dnum = Double.valueOf(cellString);
|
|
|
|
|
int inum = (int) dnum;
|
|
|
|
@ -219,6 +220,25 @@ public class ExcelOperation {
|
|
|
|
|
else {
|
|
|
|
|
tmpField.set(newObj, cellString);
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
isAddObj = false;
|
|
|
|
|
int errRownum = i+1;
|
|
|
|
|
String tmpErrString = fileName+" 第"+errRownum+"行信息有误,注意数字属性,该行请重新填写";
|
|
|
|
|
if (!rowErr.contains(tmpErrString)) {
|
|
|
|
|
rowErr.add(tmpErrString);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// 记录 excel中为空 的数据--且该条记录不记录进数据库
|
|
|
|
|
isAddObj = false;
|
|
|
|
|
int errRownum = i+1;
|
|
|
|
|
String tmpErrString = fileName+" 第"+errRownum+"行信息不完整,该行请重新填写";
|
|
|
|
|
if (!rowErr.contains(tmpErrString)) {
|
|
|
|
|
rowErr.add(tmpErrString);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|