Commit aecf5217 authored by hongguangwu's avatar hongguangwu

MVP1.6.2-工资原表识别-优化

parent 4541e249
...@@ -163,6 +163,8 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand ...@@ -163,6 +163,8 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
List<Map<String, String>> contentList; List<Map<String, String>> contentList;
// 每一行的内容map // 每一行的内容map
Map<String, String> contentMap; Map<String, String> contentMap;
// 存储每一列有值的表头
Map<String, String> titleMap = new HashMap<>();
sheets = new HSSFWorkbook(inputStream); sheets = new HSSFWorkbook(inputStream);
// sheet // sheet
HSSFSheet sheetAt; HSSFSheet sheetAt;
...@@ -198,49 +200,55 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand ...@@ -198,49 +200,55 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
columnVo = new ExcelColumnVo(); columnVo = new ExcelColumnVo();
try { try {
cell = row.getCell(cellNum); cell = row.getCell(cellNum);
if (cell.getCellType() == CellType.FORMULA) { if (cell == null) {
cell.setCellType(CellType.STRING); cellValue = "";
cellValue = cell.getStringCellValue();
} else if (CellType.STRING == cell.getCellType()) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
}
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else { } else {
try { if (cell.getCellType() == CellType.FORMULA) {
cell.setCellType(CellType.STRING);
cellValue = cell.getStringCellValue();
} else if (CellType.STRING == cell.getCellType()) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cell.setCellType(CellType.STRING);
cellValue = String.valueOf(row.getCell(cellNum).getStringCellValue());
}
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else {
cellValue = row.getCell(cellNum).getStringCellValue(); cellValue = row.getCell(cellNum).getStringCellValue();
} catch (Exception e) {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
} }
} }
} catch (Exception e) { } catch (Exception e) {
sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage()); cellValue = "";
return sheetVo; //sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage());
//return sheetVo;
} }
if (Common.isNotNull(cellValue) && dataRowFlag
&& (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue))
// 特殊身份证允许识别
|| regSpecialIdCard(cellValue, specialIdCardList))) {
dataRow = rowNum;
dataRowFlag = false;
}
columnVo.setLineNum(cellNum);
columnVo.setContent(cellValue);
if (Common.isNotNull(cellValue)) { if (Common.isNotNull(cellValue)) {
if (dataRowFlag titleMap.put(String.valueOf(cellNum), cellValue);
&& (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue)) }
// 特殊身份证允许识别 contentMap.put(String.valueOf(cellNum), cellValue);
|| regSpecialIdCard(cellValue, specialIdCardList))) { if (dataRowFlag) {
dataRow = rowNum; if (Common.isEmpty(cellValue) && titleMap.get(String.valueOf(cellNum)) != null) {
dataRowFlag = false; columnVo.setContent(titleMap.get(String.valueOf(cellNum)));
}
columnVo.setLineNum(cellNum);
columnVo.setContent(cellValue);
contentMap.put(String.valueOf(cellNum), cellValue);
if (dataRowFlag) {
columnList.add(columnVo);
} }
columnList.add(columnVo);
} }
} }
if (!dataRowFlag) { if (!dataRowFlag) {
...@@ -330,31 +338,36 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand ...@@ -330,31 +338,36 @@ public class TSalaryStandardOriginalServiceImpl extends ServiceImpl<TSalaryStand
columnVo = new ExcelColumnVo(); columnVo = new ExcelColumnVo();
try { try {
cell = row.getCell(cellNum); cell = row.getCell(cellNum);
if (cell.getCellType() == CellType.FORMULA) { if (cell == null) {
cell.setCellType(CellType.STRING); cellValue = "";
cellValue = cell.getStringCellValue(); } else {
} else if (CellType.STRING == cell.getCellType()) { if (cell.getCellType() == CellType.FORMULA) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cell.setCellType(CellType.STRING); cell.setCellType(CellType.STRING);
cellValue = String.valueOf(row.getCell(cellNum).getStringCellValue()); cellValue = cell.getStringCellValue();
} else if (CellType.STRING == cell.getCellType()) {
cellValue = row.getCell(cellNum).getStringCellValue();
} else if (CellType.NUMERIC == cell.getCellType()) {
try {
cellValue = String.valueOf(row.getCell(cellNum).getNumericCellValue());
if (cellValue.contains("E")) {
cellValue = String.valueOf(new DecimalFormat("#").format(row.getCell(cellNum).getNumericCellValue()));
}
} catch (NumberFormatException e) {
cell.setCellType(CellType.STRING);
cellValue = String.valueOf(row.getCell(cellNum).getStringCellValue());
}
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else {
cellValue = row.getCell(cellNum).getStringCellValue();
} }
} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
cellValue = String.valueOf(row.getCell(cellNum).getDateCellValue());
} else if (CellType.BOOLEAN == cell.getCellType()) {
cellValue = String.valueOf(row.getCell(cellNum).getBooleanCellValue());
} else {
cellValue = row.getCell(cellNum).getStringCellValue();
} }
} catch (Exception e) { } catch (Exception e) {
sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage()); cellValue = "";
return sheetVo; //sheetVo.setErrorInfo("请注意单元格格式,第" + (i + 1) + "个sheet,第" + (rowNum + 1) + "行第" + (cellNum + 1) + "列。" + e.getMessage());
//return sheetVo;
} }
if (Common.isNotNull(cellValue) && dataRowFlag if (Common.isNotNull(cellValue) && dataRowFlag
&& (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue)) && (((cellValue.length() == 15 || cellValue.length() == 18) && regIdCard(cellValue))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment