From b727be6889ec7af0ff1b2a9d5327de0924e52326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Thu, 20 Apr 2023 10:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/UnitTest/TestRegex.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/FengHuang/src/main/java/UnitTest/TestRegex.java b/FengHuang/src/main/java/UnitTest/TestRegex.java index 9ced76c..62bc4ac 100644 --- a/FengHuang/src/main/java/UnitTest/TestRegex.java +++ b/FengHuang/src/main/java/UnitTest/TestRegex.java @@ -4,11 +4,6 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.CharsetUtil; 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.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; @@ -36,7 +31,8 @@ public class TestRegex { } } - public static void ExportExcel(List list) throws IOException { + public static final String excelPath="c:\\录取分数导出结果.xlsx"; + public static void ExportExcel(List list, List errlist) throws IOException { String template = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\录取分数导出模板.xlsx"; //创建工作簿 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 { FileOutputStream fileOutputStreane = new FileOutputStream(file); xssfWorkbook.write(fileOutputStreane); @@ -77,8 +73,10 @@ public class TestRegex { regExp.add("(.*?)\\((\\d+)元/年(.*)\\)"); regExp.add("(.*?)\\((\\d+)元年;(.*)\\)"); regExp.add("(.*?)\\((.*?)元/年;(.*)\\)"); + regExp.add("(.*?)\\((.*?)元/年\\)"); regExp.add("(.*?)\\(学费待定;(.*)\\)"); regExp.add("(.*?)\\((\\d+)元/年\\)"); + regExp.add("(.*?)\\((\\d+)元年\\)"); regExp.add("(.*?)\\(学费待定(.*)\\)"); //模拟需要处理的串 @@ -88,6 +86,7 @@ public class TestRegex { String str1 = IoUtil.read(byteArrayInputStream, CharsetUtil.UTF_8); String[] txtArray = str1.split("\r\n"); List list = new ArrayList<>(); + List errList = new ArrayList<>(); for (int i = 0; i < txtArray.length; i++) { Record record = new Record(); @@ -108,7 +107,8 @@ public class TestRegex { if (matcher.find()) { flag = true; record.set("zhuanye", matcher.group(1)); - String xf=matcher.group(2); + String xf = matcher.group(2); + xf = xf.replace("r", ""); if (isStr2Num(xf.toString())) { record.set("xf", xf); if (matcher.groupCount() >= 3) { @@ -125,10 +125,13 @@ public class TestRegex { } list.add(record); if (!flag) { - System.out.println("有一个文本无法匹配现有正则规则,需要人工处理!"); - System.out.println(str); + Record r1 = new Record(); + r1.set("id", i + 1); + r1.set("name", str); + errList.add(r1); } } - ExportExcel(list); + ExportExcel(list, errList); + System.out.println("恭喜,结果数据导出成功,地址:"+excelPath); } }