From 2f47e734643c96d2a99dd20b056ac3c29ddb4acd 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 12:28:49 +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 | 104 ++++++++++-------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/FengHuang/src/main/java/UnitTest/TestRegex.java b/FengHuang/src/main/java/UnitTest/TestRegex.java index 5227af0..b98c07d 100644 --- a/FengHuang/src/main/java/UnitTest/TestRegex.java +++ b/FengHuang/src/main/java/UnitTest/TestRegex.java @@ -7,12 +7,10 @@ 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.awt.*; import java.io.*; import java.util.ArrayList; import java.util.List; @@ -62,6 +60,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 +94,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); @@ -167,7 +177,7 @@ 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); @@ -195,7 +205,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); }