|
|
|
@ -1,16 +1,9 @@
|
|
|
|
|
package UnitTest;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelReader;
|
|
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
|
import com.aspose.cells.Workbook;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.*;
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
@ -20,20 +13,7 @@ import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
public class TestRegex {
|
|
|
|
|
/**
|
|
|
|
|
* 查看一个字符串是否可以转换为数字
|
|
|
|
|
*
|
|
|
|
|
* @param str 字符串
|
|
|
|
|
* @return true 可以; false 不可以
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isStr2Num(String str) {
|
|
|
|
|
try {
|
|
|
|
|
Integer.parseInt(str);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String excelPath = "c:\\录取分数导出结果.xlsx";
|
|
|
|
|
public static String path = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\河南2021年专业录取分数.xlsx";
|
|
|
|
@ -62,6 +42,18 @@ public class TestRegex {
|
|
|
|
|
cellStyleTxt.setBorderRight(BorderStyle.THIN); // 右边边框
|
|
|
|
|
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
|
|
|
|
|
|
|
|
|
|
XSSFCellStyle cellStyleErr = xssfWorkbook.createCellStyle();
|
|
|
|
|
cellStyleErr.setFont(txtFont);
|
|
|
|
|
cellStyleErr.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
|
cellStyleErr.setFillForegroundColor(IndexedColors.RED.getIndex());
|
|
|
|
|
cellStyleErr.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
|
|
cellStyleErr.setWrapText(true);//设置自动换行
|
|
|
|
|
cellStyleErr.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
|
|
cellStyleErr.setBorderBottom(BorderStyle.THIN); // 底部边框
|
|
|
|
|
cellStyleErr.setBorderLeft(BorderStyle.THIN); // 左边边框
|
|
|
|
|
cellStyleErr.setBorderRight(BorderStyle.THIN); // 右边边框
|
|
|
|
|
cellStyleErr.setBorderTop(BorderStyle.THIN); // 上边边框
|
|
|
|
|
|
|
|
|
|
//表头
|
|
|
|
|
XSSFRow row = sheet1.getRow(0);
|
|
|
|
|
XSSFCell cell = row.createCell(12);
|
|
|
|
@ -84,47 +76,47 @@ public class TestRegex {
|
|
|
|
|
//调整宽度
|
|
|
|
|
sheet1.setColumnWidth(14, 512 * 50 + 184);
|
|
|
|
|
|
|
|
|
|
// //填充
|
|
|
|
|
// for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
// Record record = list.get(i);
|
|
|
|
|
// int id = record.getInt("id");
|
|
|
|
|
// String zhuanye = record.getStr("zhuanye");
|
|
|
|
|
// String xf = record.getStr("xf");
|
|
|
|
|
// String memo = record.getStr("memo");
|
|
|
|
|
// try {
|
|
|
|
|
// row = sheet1.getRow(id + 1);
|
|
|
|
|
// cell = row.createCell(12);
|
|
|
|
|
// cell.setCellValue(zhuanye);
|
|
|
|
|
// cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
//
|
|
|
|
|
// cell = row.createCell(13);
|
|
|
|
|
// cell.setCellValue(xf);
|
|
|
|
|
// cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
//
|
|
|
|
|
// cell = row.createCell(14);
|
|
|
|
|
// cell.setCellValue(memo);
|
|
|
|
|
// cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
// } catch (Exception err) {
|
|
|
|
|
// System.out.println(err.toString());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
// //写入异常数据
|
|
|
|
|
// XSSFSheet sheet2 = xssfWorkbook.getSheetAt(1);
|
|
|
|
|
// for (int i = 0; i < errlist.size(); i++) {
|
|
|
|
|
// short rowHeight = 30 * 20;
|
|
|
|
|
// Record record = errlist.get(i);
|
|
|
|
|
// XSSFRow row = sheet2.createRow(i + 2);
|
|
|
|
|
// XSSFCell cell = row.createCell(0);
|
|
|
|
|
// cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
// cell.setCellValue(record.getStr("id"));
|
|
|
|
|
// row.setHeight(rowHeight);
|
|
|
|
|
//
|
|
|
|
|
// cell = row.createCell(1);
|
|
|
|
|
// cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
// cell.setCellValue(record.getStr("name"));
|
|
|
|
|
// row.setHeight(rowHeight);
|
|
|
|
|
// }
|
|
|
|
|
//填充
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
Record record = list.get(i);
|
|
|
|
|
int id = record.getInt("id");
|
|
|
|
|
String zhuanye = record.getStr("zhuanye");
|
|
|
|
|
String xf = record.getStr("xf");
|
|
|
|
|
String memo = record.getStr("memo");
|
|
|
|
|
try {
|
|
|
|
|
row = sheet1.getRow(id + 1);
|
|
|
|
|
cell = row.createCell(12);
|
|
|
|
|
cell.setCellValue(zhuanye);
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(13);
|
|
|
|
|
cell.setCellValue(xf);
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(14);
|
|
|
|
|
cell.setCellValue(memo);
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
} catch (Exception err) {
|
|
|
|
|
System.out.println(err);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//写入异常数据
|
|
|
|
|
for (int i = 0; i < errlist.size(); i++) {
|
|
|
|
|
Record record = errlist.get(i);
|
|
|
|
|
int id = record.getInt("id");
|
|
|
|
|
row = sheet1.getRow(id + 1);
|
|
|
|
|
cell = row.createCell(12);
|
|
|
|
|
cell.setCellValue("人为处理");
|
|
|
|
|
cell.setCellStyle(cellStyleErr);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(13);
|
|
|
|
|
cell.setCellValue("人为处理");
|
|
|
|
|
cell.setCellStyle(cellStyleErr);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(14);
|
|
|
|
|
cell.setCellValue("人为处理");
|
|
|
|
|
cell.setCellStyle(cellStyleErr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//生成文件
|
|
|
|
|
File file = new File(excelPath);
|
|
|
|
@ -139,24 +131,72 @@ public class TestRegex {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 查看一个字符串是否可以转换为数字
|
|
|
|
|
*
|
|
|
|
|
* @param str 字符串
|
|
|
|
|
* @return true 可以; false 不可以
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isStr2Num(String str) {
|
|
|
|
|
try {
|
|
|
|
|
Integer.parseInt(str);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public static boolean leftMatch(String str) {
|
|
|
|
|
int ls = str.indexOf("(");
|
|
|
|
|
int rs = str.indexOf(")");
|
|
|
|
|
if (rs < ls) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean rightMatch(String str) {
|
|
|
|
|
int ls = str.lastIndexOf("(");
|
|
|
|
|
int rs = str.lastIndexOf(")");
|
|
|
|
|
if (rs < ls) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String changeMemo(String memo) {
|
|
|
|
|
if (!leftMatch(memo)) memo += "(";
|
|
|
|
|
if (!rightMatch(memo)) memo += ")";
|
|
|
|
|
//姜莹莹需求
|
|
|
|
|
memo.replace("(", "(");
|
|
|
|
|
memo.replace(")", ")");
|
|
|
|
|
memo = memo.replace("三", "3");
|
|
|
|
|
memo = memo.replace("四", "4");
|
|
|
|
|
memo = memo.replace("五", "5");
|
|
|
|
|
memo = memo.replace("六", "6");
|
|
|
|
|
return memo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//按输入顺序进行正则匹配
|
|
|
|
|
List<String> regExp = new ArrayList<>();
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元/年;(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元/年(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元年;(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元/年;(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元/年\\)");
|
|
|
|
|
regExp.add("(.*?)\\(学费待定;(.*)\\)");
|
|
|
|
|
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元/年(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元/年(.*)\\)");
|
|
|
|
|
|
|
|
|
|
regExp.add("(.*?)\\((\\d+?)元年;(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元年;(.*)\\)");
|
|
|
|
|
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元/年\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元/年\\)");
|
|
|
|
|
|
|
|
|
|
regExp.add("(.*?)\\((\\d+)元年\\)");
|
|
|
|
|
regExp.add("(.*?)\\((.*?)元年\\)");
|
|
|
|
|
|
|
|
|
|
regExp.add("(.*?)\\(学费待定;(.*)\\)");
|
|
|
|
|
regExp.add("(.*?)\\(学费待定(.*)\\)");
|
|
|
|
|
|
|
|
|
|
//模拟需要处理的串
|
|
|
|
|
List<List<Object>> source = ReadExcel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//理论与应用力学(郭永怀力学实验班)(5500元/年)
|
|
|
|
|
List<Record> list = new ArrayList<>();
|
|
|
|
|
List<Record> errList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
@ -167,7 +207,8 @@ public class TestRegex {
|
|
|
|
|
long lc = str.chars().filter(ch -> ch == '(').count();
|
|
|
|
|
long rc = str.chars().filter(ch -> ch == ')').count();
|
|
|
|
|
if (rc < lc) str += ")";
|
|
|
|
|
record.set("id", i + 1);
|
|
|
|
|
record.set("id", i - 1);
|
|
|
|
|
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
for (int j = 0; j < regExp.size(); j++) {
|
|
|
|
|
String r1 = regExp.get(j);
|
|
|
|
@ -181,12 +222,20 @@ public class TestRegex {
|
|
|
|
|
if (isStr2Num(xf.toString())) {
|
|
|
|
|
record.set("xf", xf);
|
|
|
|
|
if (matcher.groupCount() >= 3) {
|
|
|
|
|
record.set("memo", matcher.group(3));
|
|
|
|
|
String memo = matcher.group(3);
|
|
|
|
|
memo = changeMemo(memo);
|
|
|
|
|
record.set("memo", memo);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
record.set("xf", "学费待定");
|
|
|
|
|
if (matcher.groupCount() >= 2) {
|
|
|
|
|
record.set("memo", matcher.group(2));
|
|
|
|
|
String memo = matcher.group(2);
|
|
|
|
|
if (!leftMatch(memo)) memo = "(" + memo;
|
|
|
|
|
if (!rightMatch(memo)) memo += ")";
|
|
|
|
|
//姜莹莹需求
|
|
|
|
|
memo.replace("(", "(");
|
|
|
|
|
memo.replace(")", ")");
|
|
|
|
|
record.set("memo", memo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
@ -195,7 +244,7 @@ public class TestRegex {
|
|
|
|
|
list.add(record);
|
|
|
|
|
if (!flag) {
|
|
|
|
|
Record r1 = new Record();
|
|
|
|
|
r1.set("id", i + 1);
|
|
|
|
|
r1.set("id", i - 1);
|
|
|
|
|
r1.set("name", str);
|
|
|
|
|
errList.add(r1);
|
|
|
|
|
}
|
|
|
|
|