【修改】表格修改项

This commit is contained in:
huababa1
2025-10-18 15:28:35 +08:00
parent a7fd185889
commit 24210dd1b7
42 changed files with 943 additions and 99 deletions

View File

@@ -120,7 +120,7 @@ public class AutoWpsController {
* @throws Exception
*/
@PostMapping(value = "/xlsxMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public CommonResult<List<JudgementXlsxVO>> xlsxMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file, @RequestParam(value = "cell", required = false) List<String> cell) throws Exception {
public CommonResult<List<JudgementXlsxVO>> xlsxMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file, @RequestParam(value = "cell", required = false) List<String> cell,@RequestParam(value = "keyWords", required = false) String keyWords ) throws Exception {
// 手动解析JSON数组
ObjectMapper objectMapper = new ObjectMapper();
List<WpsXlsxInfoVo> wpsXlsxInfoVos = objectMapper.readValue(
@@ -128,7 +128,7 @@ public class AutoWpsController {
new TypeReference<List<WpsXlsxInfoVo>>() {
}
);
return CommonResult.success(judgementWpsExcelService.xlsxMaster(wpsXlsxInfoVos, file, cell));
return CommonResult.success(judgementWpsExcelService.xlsxMaster(wpsXlsxInfoVos, file, cell,keyWords));
}

View File

@@ -15,7 +15,7 @@ import java.util.List;
*/
public interface JudgementWpsExcelService {
List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell) throws Exception;
List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell,String keyWords) throws Exception;
List<XlsxDataInfoVO> xlsxDataInfo(MultipartFile file) throws Exception;
}

View File

@@ -17,8 +17,8 @@ public class JudgementWpsExcelServiceImpl implements JudgementWpsExcelService {
@Override
public List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell) throws Exception {
return XlsxMaster.xlsxMaster(wpsXlsxInfoVos, file,cell);
public List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell,String keyWords) throws Exception {
return XlsxMaster.xlsxMaster(wpsXlsxInfoVos, file,cell,keyWords);
}
@Override

View File

@@ -45,7 +45,7 @@ public class XlsxMaster {
* @throws IOException IO
* @throws Docx4JException 异常
*/
public static List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell) throws IOException, Docx4JException {
public static List<JudgementXlsxVO> xlsxMaster(List<WpsXlsxInfoVo> wpsXlsxInfoVos, MultipartFile file,List<String> cell,String keyWords) throws IOException, Docx4JException {
List<JudgementXlsxVO> judgementXlsxVOS = new ArrayList<>();
// 1、获取想要判断的文件地址文件流
try (InputStream inputStream = file.getInputStream()) {
@@ -91,6 +91,7 @@ public class XlsxMaster {
Class<?>[] paramTypes = {
org.apache.poi.ss.usermodel.Cell.class,
org.apache.poi.ss.usermodel.Workbook.class,
String.class
};
Method methodWithArgs = excelFunctions.getClass().getMethod(function, paramTypes);
@@ -99,7 +100,7 @@ public class XlsxMaster {
for (String cellRef : cell) {
org.apache.poi.ss.usermodel.Cell poiCell = getPoiCellFromRef(workbook, sheetName, cellRef);
if (poiCell == null) continue;
String value = (String) methodWithArgs.invoke(excelFunctions, poiCell, workbook);
String value = (String) methodWithArgs.invoke(excelFunctions, poiCell, workbook,keyWords);
if (value != null) {
if ("getCellDataFormat".equals(function)){

View File

@@ -36,13 +36,13 @@ public class CellIng {
Map.entry("SLANTEDDASHDOT", "斜点划线")
);
// 获取左框线样式
public String getLeftBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getLeftBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
BorderStyle border = style.getBorderLeft();
return border != null ? borderStyleChineseMap.getOrDefault(border.name() , border.name() ): "";
}
// 获取左框线颜色
public String getLeftBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getLeftBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFCellStyle xssfStyle = (XSSFCellStyle) style;
@@ -53,14 +53,14 @@ public class CellIng {
}
// 获取上框线样式
public String getTopBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getTopBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
BorderStyle border = style.getBorderTop();
return border != null ? borderStyleChineseMap.getOrDefault(border.name() , border.name() ): "";
}
// 获取上框线颜色
public String getTopBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getTopBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFCellStyle xssfStyle = (XSSFCellStyle) style;
@@ -70,14 +70,14 @@ public class CellIng {
}
// 获取右框线样式
public String getRightBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getRightBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
BorderStyle border = style.getBorderRight();
return border != null ? borderStyleChineseMap.getOrDefault(border.name() , border.name() ): "";
}
// 获取右框线颜色
public String getRightBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getRightBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFCellStyle xssfStyle = (XSSFCellStyle) style;
@@ -87,14 +87,14 @@ public class CellIng {
}
// 获取下框线样式
public String getBottomBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getBottomBorderStyle(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
BorderStyle border = style.getBorderBottom();
return border != null ? borderStyleChineseMap.getOrDefault(border.name() , border.name() ): "";
}
// 获取下框线颜色
public String getBottomBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb) {
public String getBottomBorderColor(Cell cell, org.apache.poi.ss.usermodel.Workbook wb,String keyWords) {
CellStyle style = cell.getCellStyle();
if (style instanceof XSSFCellStyle) {
XSSFCellStyle xssfStyle = (XSSFCellStyle) style;
@@ -103,16 +103,34 @@ public class CellIng {
return "";
}
// 获取单元格的公式表达式(字符串形式)
public String getFormulaExpression(Cell cell, Workbook wb) {
public String getFormulaExpression(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
if (cell.getCellType() == CellType.FORMULA) {
return cell.getCellFormula();
}
return "";
}
// 获取单元格的公式表达式关键字
public String getFormulaExpressionContains(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
if (cell.getCellType() == CellType.FORMULA) {
String formula = cell.getCellFormula();
// 转为小写再比较
if (formula.toLowerCase().contains(keyWords.toLowerCase())) {
return formula; // 包含关键字时返回公式内容
} else {
return ""; // 不包含关键字
}
}
return "";
}
// 获取单元格的公式计算结果(已经计算出来的值,字符串形式)
public String getFormulaResult(Cell cell, Workbook wb) {
public String getFormulaResult(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
if (cell.getCellType() != CellType.FORMULA) {
return null; // 不是公式单元格返回null
@@ -138,7 +156,7 @@ public class CellIng {
}
// 获取单元格字体名称
public String getFontName(Cell cell, Workbook wb) {
public String getFontName(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -152,7 +170,7 @@ public class CellIng {
}
// 获取单元格字体字号
public String getFontSize(Cell cell, Workbook wb) {
public String getFontSize(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -170,7 +188,7 @@ public class CellIng {
// 获取单元格字形(加粗 / 斜体
public String getFontStyle(Cell cell, Workbook wb) {
public String getFontStyle(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -190,7 +208,7 @@ public class CellIng {
// 获取单元格下划线
// 获取单元格下划线类型
public String getUnderline(Cell cell, Workbook wb) {
public String getUnderline(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -217,7 +235,7 @@ public class CellIng {
}
// 获取单元格颜色
public String getFontColor(Cell cell, Workbook wb) {
public String getFontColor(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -242,7 +260,7 @@ public class CellIng {
return "";
}
// 删除线
public static String getCellStrikeThrough(Cell cell, Workbook wb) {
public static String getCellStrikeThrough(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -251,7 +269,7 @@ public class CellIng {
}
// 上标
public static String getCellSuperScript(Cell cell, Workbook wb) {
public static String getCellSuperScript(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -260,7 +278,7 @@ public class CellIng {
}
// 下标
public static String getCellSubScript(Cell cell, Workbook wb) {
public static String getCellSubScript(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -271,7 +289,7 @@ public class CellIng {
// 获取斜下框线样式
public static String getDiagonalDownBorderStyle(Cell cell, Workbook wb) {
public static String getDiagonalDownBorderStyle(Cell cell, Workbook wb,String keyWords) {
if (cell == null || !(cell instanceof XSSFCell)) return "";
XSSFCellStyle style = (XSSFCellStyle) cell.getCellStyle();
@@ -297,7 +315,7 @@ public class CellIng {
}
// 斜下框线→颜色
public static String getDiagonalDownBorderColor(Cell cell, Workbook wb) {
public static String getDiagonalDownBorderColor(Cell cell, Workbook wb,String keyWords) {
if (cell == null || !(cell instanceof XSSFCell)) return "";
XSSFCellStyle style = (XSSFCellStyle) cell.getCellStyle();
@@ -320,7 +338,7 @@ public class CellIng {
}
// 斜上框线→样式
public static String getDiagonalUpBorderStyle(Cell cell, Workbook wb) {
public static String getDiagonalUpBorderStyle(Cell cell, Workbook wb,String keyWords) {
if (cell == null || !(cell instanceof XSSFCell)) return "";
XSSFCellStyle style = (XSSFCellStyle) cell.getCellStyle();
@@ -342,7 +360,7 @@ public class CellIng {
}
// 斜上框线→颜色
public static String getDiagonalUpBorderColor(Cell cell, Workbook wb) {
public static String getDiagonalUpBorderColor(Cell cell, Workbook wb,String keyWords) {
if (cell == null || !(cell instanceof XSSFCell)) return "";
XSSFCellStyle style = (XSSFCellStyle) cell.getCellStyle();
@@ -380,14 +398,14 @@ public class CellIng {
// ===== 获取单元格文本String =====
public String getCellText(Cell cell, Workbook wb) {
public String getCellText(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
DataFormatter formatter = new DataFormatter();
return formatter.formatCellValue(cell);
}
// ===== 获取单元格值
public String getCellValue(Cell cell, Workbook wb) {
public String getCellValue(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
switch (cell.getCellType()) {
@@ -436,7 +454,7 @@ public class CellIng {
}
// 数字格式
public static String getCellDataFormat(Cell cell, Workbook wb) {
public static String getCellDataFormat(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -444,7 +462,7 @@ public class CellIng {
}
// 水平对齐
public static String getCellHorizontalAlignment(Cell cell, Workbook wb) {
public static String getCellHorizontalAlignment(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -453,7 +471,7 @@ public class CellIng {
}
// 垂直对齐
public static String getCellVerticalAlignment(Cell cell, Workbook wb) {
public static String getCellVerticalAlignment(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -462,7 +480,7 @@ public class CellIng {
}
// 缩进
public static String getCellIndent(Cell cell, Workbook wb) {
public static String getCellIndent(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "0";
CellStyle style = cell.getCellStyle();
if (style == null) return "0";
@@ -470,7 +488,7 @@ public class CellIng {
}
// 自动换行
public static String getCellWrapText(Cell cell, Workbook wb) {
public static String getCellWrapText(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -478,7 +496,7 @@ public class CellIng {
}
// 缩小字体填充ShrinkToFit
public static String getCellShrinkToFit(Cell cell, Workbook wb) {
public static String getCellShrinkToFit(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -486,7 +504,7 @@ public class CellIng {
}
// 合并单元格
public static String getCellMerged(Cell cell, Workbook wb) {
public static String getCellMerged(Cell cell, Workbook wb,String keyWords) {
if (cell == null || wb == null) return "";
Sheet sheet = cell.getSheet();
if (sheet == null) return "";
@@ -505,7 +523,7 @@ public class CellIng {
// 文本方向rotation
public static String getCellTextRotation(Cell cell, Workbook wb) {
public static String getCellTextRotation(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "0";
CellStyle style = cell.getCellStyle();
if (style == null) return "0";
@@ -513,7 +531,7 @@ public class CellIng {
}
// 文本样式(加粗/斜体/下划线等)
public static String getCellFontStyle(Cell cell, Workbook wb) {
public static String getCellFontStyle(Cell cell, Workbook wb,String keyWords) {
if (cell == null) return "";
CellStyle style = cell.getCellStyle();
if (style == null) return "";
@@ -536,7 +554,7 @@ public class CellIng {
}
// 高度(行高)
public static String getCellRowHeight(Cell cell, Workbook wb) {
public static String getCellRowHeight(Cell cell, Workbook wb,String keyWords) {
if (cell == null || cell.getSheet() == null) return "默认";
Row row = cell.getRow();
if (row == null) return "默认";
@@ -544,7 +562,7 @@ public class CellIng {
}
// 宽度(列宽)
public static String getCellColumnWidth(Cell cell, Workbook wb) {
public static String getCellColumnWidth(Cell cell, Workbook wb,String keyWords) {
if (cell == null || cell.getSheet() == null) return "默认";
int colWidth = cell.getSheet().getColumnWidth(cell.getColumnIndex()); // 单位 1/256字符
return String.format("%.2f pt", colWidth / 256.0 * 7); // 约 7pt/字符宽,可根据字体调整

View File

@@ -1686,7 +1686,7 @@ public class SectionPage {
}
// 横向匹配
if (Math.abs(width - sh) <= tol && Math.abs(height - sw) <= tol) {
return entry.getKey() + " (横向)";
return entry.getKey();
}
}