|
|
|
@ -3,6 +3,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;
|
|
|
|
@ -33,17 +36,23 @@ public class TestRegex {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static final String excelPath = "c:\\录取分数导出结果.xlsx";
|
|
|
|
|
public static String path = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\河南2021年专业录取分数.xlsx";
|
|
|
|
|
|
|
|
|
|
public static List<List<Object>> ReadExcel() {
|
|
|
|
|
ExcelReader reader = ExcelUtil.getReader(path);
|
|
|
|
|
List<List<Object>> readAll = reader.read();
|
|
|
|
|
reader.close();
|
|
|
|
|
return readAll;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ExportExcel(List<Record> list, List<Record> errlist) throws IOException {
|
|
|
|
|
String template = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\录取分数导出模板.xlsx";
|
|
|
|
|
//创建工作簿
|
|
|
|
|
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(template));
|
|
|
|
|
//读取第一个工作表(这里的下标与list一样的,从0开始取,之后的也是如此)
|
|
|
|
|
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(path));
|
|
|
|
|
XSSFSheet sheet1 = xssfWorkbook.getSheetAt(0);
|
|
|
|
|
|
|
|
|
|
//正文与表头不是一个颜色
|
|
|
|
|
XSSFFont txtFont = xssfWorkbook.createFont();
|
|
|
|
|
txtFont.setFontHeightInPoints((short) 14); //字体大小
|
|
|
|
|
txtFont.setFontName("宋体"); //字体
|
|
|
|
|
txtFont.setFontHeightInPoints((short) 11); //字体大小
|
|
|
|
|
txtFont.setFontName("等线"); //字体
|
|
|
|
|
XSSFCellStyle cellStyleTxt = xssfWorkbook.createCellStyle();
|
|
|
|
|
cellStyleTxt.setFont(txtFont);
|
|
|
|
|
cellStyleTxt.setAlignment(HorizontalAlignment.CENTER);
|
|
|
|
@ -55,46 +64,69 @@ public class TestRegex {
|
|
|
|
|
cellStyleTxt.setBorderRight(BorderStyle.THIN); // 右边边框
|
|
|
|
|
cellStyleTxt.setBorderTop(BorderStyle.THIN); // 上边边框
|
|
|
|
|
|
|
|
|
|
//表头
|
|
|
|
|
XSSFRow row = sheet1.getRow(0);
|
|
|
|
|
XSSFCell cell = row.createCell(12);
|
|
|
|
|
cell.setCellValue("专业名称");
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
//调整宽度
|
|
|
|
|
sheet1.setColumnWidth(12, 156 * 50 + 184);
|
|
|
|
|
|
|
|
|
|
row = sheet1.getRow(0);
|
|
|
|
|
cell = row.createCell(13);
|
|
|
|
|
cell.setCellValue("学费");
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
//调整宽度
|
|
|
|
|
sheet1.setColumnWidth(13, 60 * 50 + 184);
|
|
|
|
|
|
|
|
|
|
row = sheet1.getRow(0);
|
|
|
|
|
cell = row.createCell(14);
|
|
|
|
|
cell.setCellValue("备注");
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
//调整宽度
|
|
|
|
|
sheet1.setColumnWidth(14, 512 * 50 + 184);
|
|
|
|
|
|
|
|
|
|
//填充
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
short rowHeight = 30 * 20;
|
|
|
|
|
Record record = list.get(i);
|
|
|
|
|
XSSFRow row = sheet1.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("zhuanye"));
|
|
|
|
|
row.setHeight(rowHeight);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(2);
|
|
|
|
|
cell.setCellValue(record.getStr("xf"));
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
row.setHeight(rowHeight);
|
|
|
|
|
|
|
|
|
|
cell = row.createCell(3);
|
|
|
|
|
cell.setCellValue(record.getStr("memo"));
|
|
|
|
|
cell.setCellStyle(cellStyleTxt);
|
|
|
|
|
row.setHeight(rowHeight);
|
|
|
|
|
}
|
|
|
|
|
//写入异常数据
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//生成文件
|
|
|
|
|
File file = new File(excelPath);
|
|
|
|
@ -124,25 +156,20 @@ public class TestRegex {
|
|
|
|
|
regExp.add("(.*?)\\(学费待定(.*)\\)");
|
|
|
|
|
|
|
|
|
|
//模拟需要处理的串
|
|
|
|
|
String path = "D:\\dsWork\\FengHuang\\FengHuang\\src\\main\\java\\UnitTest\\TestRegex.txt";
|
|
|
|
|
byte[] sb = FileUtil.readBytes(new File(path));
|
|
|
|
|
ByteArrayInputStream byteArrayInputStream = IoUtil.toStream(sb);
|
|
|
|
|
String str1 = IoUtil.read(byteArrayInputStream, CharsetUtil.UTF_8);
|
|
|
|
|
String[] txtArray = str1.split("\r\n");
|
|
|
|
|
List<List<Object>> source = ReadExcel();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Record> list = new ArrayList<>();
|
|
|
|
|
List<Record> errList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < txtArray.length; i++) {
|
|
|
|
|
for (int i = 1; i < source.size(); i++) {//放过表头
|
|
|
|
|
Record record = new Record();
|
|
|
|
|
|
|
|
|
|
String str = txtArray[i];
|
|
|
|
|
String str = source.get(i).get(6).toString();//第7列是专业名称
|
|
|
|
|
//计算左括号个数,右括号个数,如果右括号数小于左括号数,则添加一个右括号
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
for (int j = 0; j < regExp.size(); j++) {
|
|
|
|
|
String r1 = regExp.get(j);
|
|
|
|
|