比较两个Excel表相同主键数据
/** * * @param fileA * @param fileB * @throws Exception */ public static void readColumn(File fileA, File fileB) throws Exception { // 记录异常值 int number = 0; double yy_num_int; try { InputStream inputStream_A = new FileInputStream(fileA.getAbsoluteFile()); Workbook workbook_A = Workbook.getWorkbook(inputStream_A); InputStream inputStream_B = new FileInputStream(fileB.getAbsoluteFile()); Workbook workbook_B = Workbook.getWorkbook(inputStream_B); // 获取EXCEL分页 Sheet sheet_A = workbook_A.getSheet(0); int EXCEL_ROWS_A = sheet_A.getRows(); Sheet sheet_B = workbook_B.getSheet(0); int EXCEL_ROWS_B = sheet_B.getRows(); // A表循环读取 for (int i = 1; i < EXCEL_ROWS_A; i++) { /** * old_id = 筛选数据表对应A表编码 old_num = 筛选数据表对应A表数量 */ Cell old_id = sheet_A.getCell(3, i); Cell old_num = sheet_A.getCell(4, i); double old_num_int = new BigDecimal(old_num.getContents()).doubleValue(); // B表遍历 for (int j = 1; j < EXCEL_ROWS_B; j++) { // yy_id = B表编号 yy_num = B表数量 Cell yy_id = sheet_B.getCell(0, j); Cell yy_num = sheet_B.getCell(17, j); // 过滤列表空字符串 if ("".equals(yy_num.getContents())) { yy_num_int = 0.00; } else { yy_num_int = new BigDecimal(yy_num.getContents()).doubleValue(); } if (old_id.getContents().equals(yy_id.getContents()) && old_num_int != yy_num_int) { System.out.println("old_id:" + old_id.getContents() + ",回推6月初数量:" + old_num.getContents() + ",5月底结转:" + yy_num_int); number = number + 1; } } } System.err.println("匹配数据:" + EXCEL_ROWS_A + "异常数据:" + number); } catch (Exception e) { System.err.println("ArrayIndexOutOfBoundsException"); e.printStackTrace(); } }
记录一次小疏忽问题,6月初更换中台系统,把老系统的数据导入进来时没有进行新老数据匹配校验,进行了一个半月后产生了大量的异常数据..
废了九牛二虎之力回推数据到6月初导出了一张excel表,还好当时6月初老系统结存的数据保存了一张excel表...

浙公网安备 33010602011771号