|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package UnitTest.ImportExcel;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.QingLong.Util.AsposeUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.ImportUtil;
|
|
|
|
|
import com.dsideal.QingLong.Util.ExcelUtil;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
@ -52,9 +52,9 @@ public class ImportExcelData {
|
|
|
|
|
//用户上传的填充完的EXCEL文件
|
|
|
|
|
String f2 = path + File.separator + "school.xlsx";
|
|
|
|
|
//对比两个EXCEL文件 是不是格式一致,也就是是不是上传了正确的模板文件
|
|
|
|
|
int sheetCnt = ImportUtil.getSheetCount(upload_excel_filename);
|
|
|
|
|
int sheetCnt = ExcelUtil.getSheetCount(upload_excel_filename);
|
|
|
|
|
for (int i = 0; i < sheetCnt; i++) {
|
|
|
|
|
List<Map.Entry<Integer, Integer>> chayi = ImportUtil.checkYiZhi(f1, f2, i);
|
|
|
|
|
List<Map.Entry<Integer, Integer>> chayi = ExcelUtil.checkYiZhi(f1, f2, i);
|
|
|
|
|
if (chayi.size() > 0) {
|
|
|
|
|
System.out.println("第" + (i + 1) + "个Sheet表检查过程中发现与要求上传的模板不一致,请重新下载模板填写完成后再次上传!");
|
|
|
|
|
return;
|
|
|
|
@ -71,18 +71,18 @@ public class ImportExcelData {
|
|
|
|
|
//Sheet表
|
|
|
|
|
XSSFSheet sheet = wb.getSheetAt(i);
|
|
|
|
|
//移除所有批注
|
|
|
|
|
ImportUtil.RemoveAllComment(sheet);
|
|
|
|
|
ExcelUtil.RemoveAllComment(sheet);
|
|
|
|
|
|
|
|
|
|
//数据起始行
|
|
|
|
|
Record r = ImportUtil.getSheetConfig(upload_excel_filename, i);
|
|
|
|
|
Record r = ExcelUtil.getSheetConfig(upload_excel_filename, i);
|
|
|
|
|
int data_start_row = r.getInt("data_start_row");
|
|
|
|
|
//恢复背景色
|
|
|
|
|
ImportUtil.resetStyle(wb, sheet, data_start_row);
|
|
|
|
|
ExcelUtil.resetStyle(wb, sheet, data_start_row);
|
|
|
|
|
|
|
|
|
|
//数据有效行数
|
|
|
|
|
int lastRowNum = sheet.getLastRowNum();
|
|
|
|
|
//遍历每一列
|
|
|
|
|
List<Record> list = ImportUtil.getSheetMapping(upload_excel_filename, i);
|
|
|
|
|
List<Record> list = ExcelUtil.getSheetMapping(upload_excel_filename, i);
|
|
|
|
|
for (Record record : list) {//列
|
|
|
|
|
int excel_column_idx = record.getInt("excel_column_idx");//第几列
|
|
|
|
|
String column_type = record.getStr("column_type");//类型
|
|
|
|
@ -93,9 +93,9 @@ public class ImportExcelData {
|
|
|
|
|
// 非空项目未填写
|
|
|
|
|
for (int j = data_start_row; j <= lastRowNum; j++) {//行
|
|
|
|
|
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
|
|
|
|
|
if (StrKit.isBlank(ImportUtil.getValue(cell).toString())) {
|
|
|
|
|
ImportUtil.addComment(wb, cell, "此处不能为空!");
|
|
|
|
|
ImportUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
if (StrKit.isBlank(ExcelUtil.getValue(cell).toString())) {
|
|
|
|
|
ExcelUtil.addComment(wb, cell, "此处不能为空!");
|
|
|
|
|
ExcelUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -104,11 +104,11 @@ public class ImportExcelData {
|
|
|
|
|
if (!StrKit.isBlank(options)) {
|
|
|
|
|
for (int j = data_start_row; j <= lastRowNum; j++) {//行
|
|
|
|
|
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
|
|
|
|
|
String value = ImportUtil.getValue(cell).toString();
|
|
|
|
|
String value = ExcelUtil.getValue(cell).toString();
|
|
|
|
|
if (StrKit.isBlank(value)) value = "&*^&Y&*(&*(&*()*(";
|
|
|
|
|
if (options.indexOf(value) < 0) {
|
|
|
|
|
ImportUtil.addComment(wb, cell, "未从指定范围内选择有效值!");
|
|
|
|
|
ImportUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
ExcelUtil.addComment(wb, cell, "未从指定范围内选择有效值!");
|
|
|
|
|
ExcelUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -116,19 +116,19 @@ public class ImportExcelData {
|
|
|
|
|
// 检查数据类型是不是和规定的不兼容
|
|
|
|
|
for (int j = data_start_row; j <= lastRowNum; j++) {//行
|
|
|
|
|
XSSFCell cell = sheet.getRow(j).getCell(excel_column_idx);
|
|
|
|
|
Object obj = ImportUtil.getValue(cell);
|
|
|
|
|
Object obj = ExcelUtil.getValue(cell);
|
|
|
|
|
|
|
|
|
|
if (column_type.equals("Integer") && !ImportUtil.isInteger(obj.toString())) {//要求整数,实际不是整数
|
|
|
|
|
ImportUtil.addComment(wb, cell, "要求是整数,实际数据类型不是整数!");
|
|
|
|
|
ImportUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
if (column_type.equals("Integer") && !ExcelUtil.isInteger(obj.toString())) {//要求整数,实际不是整数
|
|
|
|
|
ExcelUtil.addComment(wb, cell, "要求是整数,实际数据类型不是整数!");
|
|
|
|
|
ExcelUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
flag = false;
|
|
|
|
|
} else if (column_type.equals("Double") && !ImportUtil.isDouble(obj.toString())) {//要求是浮点数,实际不是浮点数
|
|
|
|
|
ImportUtil.addComment(wb, cell, "要求是小数,实际数据类型不是小数!");
|
|
|
|
|
ImportUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
} else if (column_type.equals("Double") && !ExcelUtil.isDouble(obj.toString())) {//要求是浮点数,实际不是浮点数
|
|
|
|
|
ExcelUtil.addComment(wb, cell, "要求是小数,实际数据类型不是小数!");
|
|
|
|
|
ExcelUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
flag = false;
|
|
|
|
|
} else if (column_type.equals("Date") && !ImportUtil.isDate(obj.toString())) {//要求是日期,实际不是日期
|
|
|
|
|
ImportUtil.addComment(wb, cell, "要求是日期格式,实际数据类型不是日期格式!");
|
|
|
|
|
ImportUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
} else if (column_type.equals("Date") && !ExcelUtil.isDate(obj.toString())) {//要求是日期,实际不是日期
|
|
|
|
|
ExcelUtil.addComment(wb, cell, "要求是日期格式,实际数据类型不是日期格式!");
|
|
|
|
|
ExcelUtil.fillColor(wb, cell, IndexedColors.YELLOW.getIndex());
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -151,7 +151,7 @@ public class ImportExcelData {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查通过,导入数据
|
|
|
|
|
for (int i = 0; i < sheetCnt; i++) ImportUtil.importData(upload_excel_filename, wb, i, bureau_id, person_id);
|
|
|
|
|
for (int i = 0; i < sheetCnt; i++) ExcelUtil.importData(upload_excel_filename, wb, i, bureau_id, person_id);
|
|
|
|
|
|
|
|
|
|
System.out.println("恭喜,所有数据成功导入!");
|
|
|
|
|
//关闭Excel
|
|
|
|
|