【新增】 验证pptx方法
This commit is contained in:
@@ -98,15 +98,18 @@ public class AutoWpsController {
|
|||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/slideMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
// @PostMapping(value = "/slideMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
public CommonResult<List<JudgementSlidesVO>> slideMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file) throws Exception {
|
@PostMapping(value = "/slideMaster")
|
||||||
// 手动解析JSON数组
|
public CommonResult<List<JudgementSlidesVO>> slideMaster(@RequestBody List<WpsSlideInfoVo> wpsSlideInfoVos) throws Exception {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// public CommonResult<List<JudgementSlidesVO>> slideMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file) throws Exception {
|
||||||
List<WpsSlideInfoVo> wpsSlideInfoVos = objectMapper.readValue(
|
// 手动解析JSON数组
|
||||||
jsonData,
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
new TypeReference<List<WpsSlideInfoVo>>() {
|
// List<WpsSlideInfoVo> wpsSlideInfoVos = objectMapper.readValue(
|
||||||
}
|
// jsonData,
|
||||||
);
|
// new TypeReference<List<WpsSlideInfoVo>>() {
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
MultipartFile file = null;
|
||||||
return CommonResult.success(judgementWpsPptxService.slideMaster(wpsSlideInfoVos, file));
|
return CommonResult.success(judgementWpsPptxService.slideMaster(wpsSlideInfoVos, file));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@@ -74,7 +74,7 @@ public class AutoToolsController {
|
|||||||
// 1、创建对象
|
// 1、创建对象
|
||||||
StuPaperScoreInfoVo stuPaperScoreInfoVos = new StuPaperScoreInfoVo();
|
StuPaperScoreInfoVo stuPaperScoreInfoVos = new StuPaperScoreInfoVo();
|
||||||
// 2、查询学生试卷信息
|
// 2、查询学生试卷信息
|
||||||
StuScoreVo stuScoreVo = stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId());
|
StuScoreVo stuScoreVo = stuPaperScoreService.getStuScore(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId());
|
||||||
stuPaperScoreInfoVos.setStuInfoReqVo(stuScoreVo);
|
stuPaperScoreInfoVos.setStuInfoReqVo(stuScoreVo);
|
||||||
// 3、查询学生试卷得分信息
|
// 3、查询学生试卷得分信息
|
||||||
stuPaperScoreInfoVos.setStuPaperScoreDOList(stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId()));
|
stuPaperScoreInfoVos.setStuPaperScoreDOList(stuPaperScoreService.findByStuIDAndPaperId(stuPaperReqVo.getStuId(),stuPaperReqVo.getPaperId(), stuPaperReqVo.getTemporaryId()));
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
|
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
|
||||||
|
|
||||||
|
import jakarta.xml.bind.JAXBElement;
|
||||||
|
import jakarta.xml.bind.JAXBException;
|
||||||
import org.docx4j.dml.*;
|
import org.docx4j.dml.*;
|
||||||
import org.docx4j.openpackaging.packages.PresentationMLPackage;
|
import org.docx4j.jaxb.XPathBinderAssociationIsPartialException;
|
||||||
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
|
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
|
||||||
import org.pptx4j.pml.CTSlideTiming;
|
import org.pptx4j.pml.CTSlideTiming;
|
||||||
|
import org.pptx4j.pml.CTTimeNodeList;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.text.DecimalFormat;
|
import java.util.List;
|
||||||
|
|
||||||
public class Shape {
|
public class ShapePage {
|
||||||
|
|
||||||
// 大小 - 高度
|
// 大小 - 高度
|
||||||
public static String getShapeSizeHeight(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
|
public static String getShapeSizeHeight(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
|
||||||
@@ -355,11 +358,16 @@ public class Shape {
|
|||||||
|
|
||||||
|
|
||||||
// 动画 效果
|
// 动画 效果
|
||||||
public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
|
public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing, SlidePart slidePart) throws JAXBException, XPathBinderAssociationIsPartialException {
|
||||||
// 获取形状中的ID
|
// 获取形状中的ID
|
||||||
if (sp == null) return "无动画";
|
if (sp == null) return "无动画";
|
||||||
long spId = sp.getNvSpPr().getCNvPr().getId();
|
long spId = sp.getNvSpPr().getCNvPr().getId();
|
||||||
// 获取动画效果
|
// 获取动画效果
|
||||||
|
// 1. 查询所有 p:spTgt 节点(形状目标)
|
||||||
|
List<Object> shapeTargets = slidePart.getJAXBNodesViaXPath("//p:spTgt", false);
|
||||||
|
for (Object target : shapeTargets) {
|
||||||
|
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
|
|||||||
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
|
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
|
||||||
import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart;
|
import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart;
|
||||||
import org.docx4j.wml.P;
|
import org.docx4j.wml.P;
|
||||||
|
import org.pptx4j.pml.CTSlideTiming;
|
||||||
import org.pptx4j.pml.GroupShape;
|
import org.pptx4j.pml.GroupShape;
|
||||||
import org.pptx4j.pml.Shape;
|
import org.pptx4j.pml.Shape;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -15,6 +16,7 @@ import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo;
|
|||||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||||
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.paragraph.Paragraphs;
|
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.paragraph.Paragraphs;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -24,12 +26,14 @@ import java.util.List;
|
|||||||
public class SlideMaster {
|
public class SlideMaster {
|
||||||
|
|
||||||
public static List<JudgementSlidesVO> slideMaster(List<WpsSlideInfoVo> wpsSlideInfoVos, MultipartFile file) throws IOException, Docx4JException {
|
public static List<JudgementSlidesVO> slideMaster(List<WpsSlideInfoVo> wpsSlideInfoVos, MultipartFile file) throws IOException, Docx4JException {
|
||||||
|
File files = new File("E:\\Project\\Exam\\Software\\Temp\\1.pptx");
|
||||||
List<JudgementSlidesVO> judgementSlidesVOS = new ArrayList<>();
|
List<JudgementSlidesVO> judgementSlidesVOS = new ArrayList<>();
|
||||||
// 1、获取想要判断的文件地址(文件流)
|
// 1、获取想要判断的文件地址(文件流)
|
||||||
try (InputStream inputStream = file.getInputStream()) {
|
// try (InputStream inputStream = file.getInputStream()) {
|
||||||
|
try {
|
||||||
// 加载 .pptx 文件
|
// 加载 .pptx 文件
|
||||||
PresentationMLPackage ppt =
|
PresentationMLPackage ppt =
|
||||||
(PresentationMLPackage) OpcPackage.load(inputStream);
|
(PresentationMLPackage) OpcPackage.load(files);
|
||||||
// 你可以在这里处理 ppt,比如读取文字、页数等
|
// 你可以在这里处理 ppt,比如读取文字、页数等
|
||||||
for (WpsSlideInfoVo wpsSlideInfoVo : wpsSlideInfoVos) {
|
for (WpsSlideInfoVo wpsSlideInfoVo : wpsSlideInfoVos) {
|
||||||
// 幻灯片位置(第几张幻灯片)
|
// 幻灯片位置(第几张幻灯片)
|
||||||
@@ -50,7 +54,7 @@ public class SlideMaster {
|
|||||||
if (type.equals("shape")) {
|
if (type.equals("shape")) {
|
||||||
// 查询幻灯片图片
|
// 查询幻灯片图片
|
||||||
List<SlidePart> slideParts = ppt.getMainPresentationPart().getSlideParts();
|
List<SlidePart> slideParts = ppt.getMainPresentationPart().getSlideParts();
|
||||||
int slideIndexFoFile = 1;
|
int slideIndexFoFile = 0;
|
||||||
for (SlidePart slidePart : slideParts) {
|
for (SlidePart slidePart : slideParts) {
|
||||||
// 获取幻灯片内容
|
// 获取幻灯片内容
|
||||||
slideIndexFoFile++;
|
slideIndexFoFile++;
|
||||||
@@ -58,8 +62,9 @@ public class SlideMaster {
|
|||||||
// 查询幻灯片
|
// 查询幻灯片
|
||||||
// 遍历 shape tree 中的 sp(shape)元素
|
// 遍历 shape tree 中的 sp(shape)元素
|
||||||
GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree();
|
GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree();
|
||||||
|
CTSlideTiming timing = slidePart.getJaxbElement().getTiming();
|
||||||
List<Object> shapes = spTree.getSpOrGrpSpOrGraphicFrame();
|
List<Object> shapes = spTree.getSpOrGrpSpOrGraphicFrame();
|
||||||
int shapeIndexFoFile = 1;
|
int shapeIndexFoFile = 0;
|
||||||
for (Object shapeObj : shapes) {
|
for (Object shapeObj : shapes) {
|
||||||
shapeIndexFoFile++;
|
shapeIndexFoFile++;
|
||||||
if (shapeObj instanceof Shape) {
|
if (shapeObj instanceof Shape) {
|
||||||
@@ -67,13 +72,13 @@ public class SlideMaster {
|
|||||||
if (shapeIndex.equals(String.valueOf(shapeIndexFoFile))) {
|
if (shapeIndex.equals(String.valueOf(shapeIndexFoFile))) {
|
||||||
// 查询出具体想要查询哪个段落的数据
|
// 查询出具体想要查询哪个段落的数据
|
||||||
// 目标对象
|
// 目标对象
|
||||||
Shape shapeFunction = new Shape();
|
ShapePage shapeFunction = new ShapePage();
|
||||||
// 获取参数中类型的定义
|
// 获取参数中类型的定义
|
||||||
Class<?>[] paramTypes = {Shape.class};
|
Class<?>[] paramTypes = {Shape.class, CTSlideTiming.class, SlidePart.class};
|
||||||
// 带参数的方法调用示例
|
// 带参数的方法调用示例
|
||||||
Method methodWithArgs = shapeFunction.getClass().getMethod(function, paramTypes);
|
Method methodWithArgs = shapeFunction.getClass().getMethod(function, paramTypes);
|
||||||
// 实际参数值
|
// 实际参数值
|
||||||
Object[] arguments = {shape};
|
Object[] arguments = {shape, timing, slidePart};
|
||||||
String value = (String) methodWithArgs.invoke(shapeFunction, arguments);
|
String value = (String) methodWithArgs.invoke(shapeFunction, arguments);
|
||||||
System.out.println(value);
|
System.out.println(value);
|
||||||
}
|
}
|
||||||
|
@@ -136,4 +136,22 @@ public class SlideUtils {
|
|||||||
return new DecimalFormat("#.##").format(d); // 保留 1~2 位,去掉多余 0
|
return new DecimalFormat("#.##").format(d); // 保留 1~2 位,去掉多余 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String rgbBytesToHex(byte[] val) {
|
||||||
|
if (val == null || val.length != 3) return "000000";
|
||||||
|
return String.format("%02X%02X%02X", val[0] & 0xFF, val[1] & 0xFF, val[2] & 0xFF);
|
||||||
|
}
|
||||||
|
public static String extractAlpha(java.util.List<CTPositiveFixedPercentage> alphas) {
|
||||||
|
if (alphas != null && !alphas.isEmpty()) {
|
||||||
|
double pct = alphas.get(0).getVal() / 1000.0;
|
||||||
|
return String.format("%.0f%%", pct);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static int iOr0(BigInteger bi) {
|
||||||
|
return bi == null ? 0 : bi.intValue();
|
||||||
|
}
|
||||||
|
public static String fmt(double d) {
|
||||||
|
return (Math.round(d * 100.0) / 100.0) + ""; // 保留 2 位小数
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user