【修改】excel,word,ps考点

This commit is contained in:
huababa1
2025-08-26 22:53:37 +08:00
parent 10823a0ec4
commit 3dc91625fb
6 changed files with 260 additions and 301 deletions

View File

@@ -102,11 +102,19 @@ public class XlsxMaster {
String value = (String) methodWithArgs.invoke(excelFunctions, poiCell, workbook);
if (value != null) {
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
""+sheetName+""+docxFunction +"@"+cellRef+ "@" + value,
""+sheetName+""+firstName +""+cellRef+""+ examName + value
);
if ("getCellDataFormat".equals(function)){
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
""+sheetName+""+docxFunction +"@"+cellRef+ "@" + value,
""+sheetName+""+firstName +""+cellRef+""+ examName + ""
);
}else {
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
""+sheetName+""+docxFunction +"@"+cellRef+ "@" + value,
""+sheetName+""+firstName +""+cellRef+""+ examName + value
);
}
}
}
}
@@ -129,11 +137,19 @@ public class XlsxMaster {
// for (String cellRef : cellRefs) {
String value = (String) methodWithArgs.invoke(rangingFunctions, rangeStr, workbook,sheetNum);
if (value != null) {
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
"" + sheetName + "" + docxFunction + "@" + rangeStr + "@" + value,
"" + sheetName + "" + firstName + "" + rangeStr + "" + examName + value
);
if ("printCellFormatNumStyle".equals(function)){
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
""+sheetName+""+docxFunction +"@"+rangeStr+ "@" + value,
""+sheetName+""+firstName +""+rangeStr+""+ examName + ""
);
}else {
judgementXlsxVOS = setJudgementXlsx(
judgementXlsxVOS,
""+sheetName+""+docxFunction +"@"+rangeStr+ "@" + value,
""+sheetName+""+firstName +""+rangeStr+""+ examName + value
);
}
}
// }
}

View File

@@ -329,65 +329,24 @@ public class ChartHandler {
return "未找到图表位置";
}
/** 图表-设计 - 图表样式 */
/** 图表-设计 - 图表样式*\
public String getChartStyle(XSSFChart chart, XSSFSheet sheet) {
if (chart == null) return "无图表";
try {
Node chartNode = chart.getCTChartSpace().getDomNode();
// 先尝试取 c14:style
NodeList c14StyleNodes = ((Element) chartNode)
.getElementsByTagNameNS("http://schemas.microsoft.com/office/drawing/2007/8/2/chart", "style");
if (c14StyleNodes.getLength() > 0) {
String val = ((Element) c14StyleNodes.item(0)).getAttribute("val");
int styleId = Integer.parseInt(val);
// 映射 101114 → 114
if (styleId >= 101 && styleId <= 114) {
styleId -= 100;
}
return "样式" + styleId;
}
// 再尝试取 c:style
NodeList cStyleNodes = ((Element) chartNode)
.getElementsByTagNameNS("http://schemas.openxmlformats.org/drawingml/2006/chart", "style");
if (cStyleNodes.getLength() > 0) {
String val = ((Element) cStyleNodes.item(0)).getAttribute("val");
int styleId = Integer.parseInt(val);
return "样式" + styleId;
}
return "未定义样式";
} catch (Exception e) {
e.printStackTrace();
return "解析图表样式时出错: " + e.getMessage();
}
}
/**
* 打印图表对应的 XML
*/
public static void printChartXml(XSSFChart chart) {
if (chart == null) {
System.out.println("无图表");
return;
}
try {
PackagePart part = chart.getPackagePart();
try (InputStream is = part.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
String xml = chart.getCTChartSpace().xmlText();
System.out.println(xml);
} catch (Exception e) {
e.printStackTrace();
System.out.println("读取图表XML失败: " + e.getMessage());
}
}

View File

@@ -10,7 +10,9 @@ import org.apache.poi.xssf.usermodel.*;
import pc.exam.pp.module.judgement.utils.wps_word.utils.ColorUtils;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -400,10 +402,17 @@ public class RangIng {
if (cell.getCellType() == CellType.FORMULA) {
CellType evaluatedType = evaluator.evaluateFormulaCell(cell);
String val;
String val = null;
switch (evaluatedType) {
case NUMERIC:
val = String.valueOf(cell.getNumericCellValue());
if (DateUtil.isCellDateFormatted(cell)) {
// 如果是日期格式,格式化为 yyyy/M/d
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/d");
val = sdf.format(date);
} else {
val = String.valueOf(cell.getNumericCellValue());
}
break;
case STRING:
val = cell.getStringCellValue();
@@ -414,8 +423,6 @@ public class RangIng {
case ERROR:
val = "错误值";
break;
default:
val = null;
}
if (val != null) {
@@ -430,6 +437,7 @@ public class RangIng {
//范围 - 填充 背景色
public String getFillBgColors(String cellRefRange, Workbook workbook, int sheetIndex) {
List<String> cellRefs = getCellRefsInRange(cellRefRange);

View File

@@ -9,6 +9,7 @@ import org.docx4j.dml.wordprocessingDrawing.Inline;
import org.docx4j.mce.AlternateContent;
import org.docx4j.model.structure.DocumentModel;
import org.docx4j.model.structure.HeaderFooterPolicy;
import org.docx4j.model.structure.PageDimensions;
import org.docx4j.model.structure.SectionWrapper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
@@ -209,76 +210,37 @@ public class SectionPage {
}
}
// 每行字符数
// 每行字符数 + 每页行数
// public static String getSectionPageCharNumber(P paragraph,
// HeaderFooterPolicy hfp,
// WordprocessingMLPackage wordMLPackage,
// List<SectionWrapper> sections) {
// try {
// if (sections == null || sections.isEmpty()) {
// return "【没有节信息】";
// }
//
// // 这里只取第一个节(通常文档只有一个节,如果有多个可以 for 循环)
// SectionWrapper sectionWrapper = sections.get(0);
// SectPr sectPr = sectionWrapper.getSectPr();
// if (sectPr == null) {
// return "【无 SectPr 信息】";
// }
// System.out.println("==============");
//
//
//
// // 页面属性
// SectPr.PgSz pgSz = sectPr.getPgSz();
// SectPr.PgMar pgMar = sectPr.getPgMar();
// if (pgSz == null || pgMar == null) {
// return "【无页面设置】";
// }
//
// int pageW = pgSz.getW().intValue(); // 页面宽度 (twip)
// int pageH = pgSz.getH().intValue(); // 页面高度 (twip)
// int left = pgMar.getLeft().intValue();
// int right = pgMar.getRight().intValue();
// int top = pgMar.getTop().intValue();
// int bottom = pgMar.getBottom().intValue();
//
// // 可用区域
// int availableWidth = pageW - left - right;
// int availableHeight = pageH - top - bottom;
//
// // 网格设置
// CTDocGrid grid = sectPr.getDocGrid();
// if (grid == null) {
// return "【未设置文档网格】";
// }
//
// StringBuilder sb = new StringBuilder("【页面设置(文档网格)】");
//
// // 每行字符数
// if (grid.getCharSpace() != null) {
// int charSpace = grid.getCharSpace().intValue();
// if (charSpace > 0) {
// int charsPerLine = Math.round((float) availableWidth / charSpace);
// sb.append("【每行字符数】").append(charsPerLine).append(" 字/行");
// }
// }
//
// // 每页行数
// if (grid.getLinePitch() != null) {
// int linePitch = grid.getLinePitch().intValue();
// if (linePitch > 0) {
// int linesPerPage = Math.round((float) availableHeight / linePitch);
// sb.append("【每页行数】").append(linesPerPage).append(" 行/页");
// }
// }
//
// return sb.toString();
//
// } catch (Exception e) {
// return "【计算异常】" + e.getMessage();
// }
// }
public static String getSectionPageCharNumber(P paragraph,
HeaderFooterPolicy hfp,
WordprocessingMLPackage wordMLPackage,
List<SectionWrapper> sections) {
if (paragraph == null || paragraph.getPPr() == null) return "未知";
SectPr sectPr = paragraph.getPPr().getSectPr();
if (sectPr == null) return "";
CTDocGrid docGrid = sectPr.getDocGrid();
if (docGrid == null || docGrid.getCharSpace() == null) {
return "未设置";
}
// 取 charSpace (每个字的宽度, twips)
int charSpace = docGrid.getCharSpace().intValue();
// 计算可写宽度(页面宽度 - 左右边距)
PageDimensions pageDim = new PageDimensions(sectPr);
int availableWidth = pageDim.getWritableWidthTwips();
// 反推字数 (四舍五入)
int charsPerLine = Math.round((float) availableWidth / (float) charSpace);
System.out.println("charSpace = " + charSpace);
System.out.println("可写宽度 = " + availableWidth);
System.out.println("反推字数 = " + charsPerLine);
return "【每行字符数】" + charsPerLine + " 字/行";
}

View File

@@ -1257,28 +1257,52 @@ public class TextInfo {
return judgementWordsVOS;
}
// 文本内容
public static String getTextValue(List<JudgementWordsVO> judgementWordsVOS, Anchor anchor, int betoLong,WordprocessingMLPackage wordMLPackage){
public static String getTextValue(List<JudgementWordsVO> judgementWordsVOS,
Anchor anchor,
int betoLong,
WordprocessingMLPackage wordMLPackage) {
Object graphicData = anchor.getGraphic().getGraphicData().getAny().get(0);
// 正确处理 JAXBElement
if (graphicData instanceof JAXBElement) {
JAXBElement<?> jaxbElement = (JAXBElement<?>) graphicData;
Object value = jaxbElement.getValue();
// 现在可以尝试转换为实际类型
if (value.getClass().getName().contains("CTWordprocessingShape")) {
if (value instanceof CTWordprocessingShape) {
// 文本内容
CTWordprocessingShape textInfo = (CTWordprocessingShape) value;
String textValue = textInfo.getTxbx().getTxbxContent().getContent().toString();
if (textValue!=null){
return textValue;
if (value instanceof CTWordprocessingShape) {
CTWordprocessingShape textInfo = (CTWordprocessingShape) value;
if (textInfo.getTxbx() != null && textInfo.getTxbx().getTxbxContent() != null) {
StringBuilder sb = new StringBuilder();
List<Object> contents = textInfo.getTxbx().getTxbxContent().getContent();
for (Object obj : contents) {
// 解包 JAXBElement
Object unwrapped = (obj instanceof JAXBElement) ? ((JAXBElement<?>) obj).getValue() : obj;
if (unwrapped instanceof P) {
P para = (P) unwrapped;
List<Object> paraContents = para.getContent();
for (Object pc : paraContents) {
Object inner = (pc instanceof JAXBElement) ? ((JAXBElement<?>) pc).getValue() : pc;
if (inner instanceof R) {
R run = (R) inner;
for (Object rc : run.getContent()) {
Object rcVal = (rc instanceof JAXBElement) ? ((JAXBElement<?>) rc).getValue() : rc;
if (rcVal instanceof Text) {
sb.append(((Text) rcVal).getValue());
}
}
}
}
sb.append("\n"); // 段落换行
}
}
return sb.toString().trim();
}
}
}
return null;
return "";
}
// 文字方向
public static String getTextVert(List<JudgementWordsVO> judgementWordsVOS, Anchor anchor, int betoLong, WordprocessingMLPackage wordMLPackage) {
if (anchor == null