main
黄海 2 years ago
parent e58575a51a
commit b727be6889

@ -4,11 +4,6 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.Record;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
@ -36,7 +31,8 @@ public class TestRegex {
} }
} }
public static void ExportExcel(List<Record> list) throws IOException { public static final String excelPath="c:\\录取分数导出结果.xlsx";
public static void ExportExcel(List<Record> list, List<Record> errlist) throws IOException {
String template = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\录取分数导出模板.xlsx"; String template = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\录取分数导出模板.xlsx";
//创建工作簿 //创建工作簿
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(template)); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(template));
@ -57,7 +53,7 @@ public class TestRegex {
} }
//生成文件 //生成文件
File file = new File("c:\\录取分数导出结果.xlsx"); File file = new File(excelPath);
try { try {
FileOutputStream fileOutputStreane = new FileOutputStream(file); FileOutputStream fileOutputStreane = new FileOutputStream(file);
xssfWorkbook.write(fileOutputStreane); xssfWorkbook.write(fileOutputStreane);
@ -77,8 +73,10 @@ public class TestRegex {
regExp.add("(.*?)\\((\\d+)元/年(.*)\\)"); regExp.add("(.*?)\\((\\d+)元/年(.*)\\)");
regExp.add("(.*?)\\((\\d+)元年;(.*)\\)"); regExp.add("(.*?)\\((\\d+)元年;(.*)\\)");
regExp.add("(.*?)\\((.*?)元/年;(.*)\\)"); regExp.add("(.*?)\\((.*?)元/年;(.*)\\)");
regExp.add("(.*?)\\((.*?)元/年\\)");
regExp.add("(.*?)\\(学费待定;(.*)\\)"); regExp.add("(.*?)\\(学费待定;(.*)\\)");
regExp.add("(.*?)\\((\\d+)元/年\\)"); regExp.add("(.*?)\\((\\d+)元/年\\)");
regExp.add("(.*?)\\((\\d+)元年\\)");
regExp.add("(.*?)\\(学费待定(.*)\\)"); regExp.add("(.*?)\\(学费待定(.*)\\)");
//模拟需要处理的串 //模拟需要处理的串
@ -88,6 +86,7 @@ public class TestRegex {
String str1 = IoUtil.read(byteArrayInputStream, CharsetUtil.UTF_8); String str1 = IoUtil.read(byteArrayInputStream, CharsetUtil.UTF_8);
String[] txtArray = str1.split("\r\n"); String[] txtArray = str1.split("\r\n");
List<Record> list = new ArrayList<>(); List<Record> list = new ArrayList<>();
List<Record> errList = new ArrayList<>();
for (int i = 0; i < txtArray.length; i++) { for (int i = 0; i < txtArray.length; i++) {
Record record = new Record(); Record record = new Record();
@ -108,7 +107,8 @@ public class TestRegex {
if (matcher.find()) { if (matcher.find()) {
flag = true; flag = true;
record.set("zhuanye", matcher.group(1)); record.set("zhuanye", matcher.group(1));
String xf=matcher.group(2); String xf = matcher.group(2);
xf = xf.replace("r", "");
if (isStr2Num(xf.toString())) { if (isStr2Num(xf.toString())) {
record.set("xf", xf); record.set("xf", xf);
if (matcher.groupCount() >= 3) { if (matcher.groupCount() >= 3) {
@ -125,10 +125,13 @@ public class TestRegex {
} }
list.add(record); list.add(record);
if (!flag) { if (!flag) {
System.out.println("有一个文本无法匹配现有正则规则,需要人工处理!"); Record r1 = new Record();
System.out.println(str); r1.set("id", i + 1);
r1.set("name", str);
errList.add(r1);
} }
} }
ExportExcel(list); ExportExcel(list, errList);
System.out.println("恭喜,结果数据导出成功,地址:"+excelPath);
} }
} }

Loading…
Cancel
Save