【修改】 pptx 的基础方法调试
This commit is contained in:
@@ -14,9 +14,11 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import pc.exam.pp.framework.common.pojo.CommonResult;
|
||||
import pc.exam.pp.module.infra.controller.admin.file.vo.file.FileUploadReqVO;
|
||||
import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsDocxInfoVo;
|
||||
import pc.exam.pp.module.judgement.controller.admin.AutoWps.vo.WpsSlideInfoVo;
|
||||
import pc.exam.pp.module.judgement.service.wps_excel.JudgementWpsExcelService;
|
||||
import pc.exam.pp.module.judgement.service.wps_pptx.JudgementWpsPptxService;
|
||||
import pc.exam.pp.module.judgement.service.wps_word.JudgementWpsWordService;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.DocxDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_word.docx4j.vo.JudgementWordsVO;
|
||||
@@ -80,6 +82,22 @@ public class AutoWpsController {
|
||||
);
|
||||
return CommonResult.success(judgementWpsWordService.docxMaster(wpsDocxInfoVos, file));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定考点的数据
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping(value = "/slideMaster", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public CommonResult<List<JudgementSlidesVO>> slideMaster(@RequestPart("data") String jsonData, @RequestPart("file") MultipartFile file) throws Exception {
|
||||
// 手动解析JSON数组
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<WpsSlideInfoVo> wpsSlideInfoVos = objectMapper.readValue(
|
||||
jsonData,
|
||||
new TypeReference<List<WpsSlideInfoVo>>() {
|
||||
}
|
||||
);
|
||||
return CommonResult.success(judgementWpsPptxService.slideMaster(wpsSlideInfoVos, file));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import pc.exam.pp.module.judgement.controller.admin.Wps.dto.WpsPptxJudgementDto;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.JudgementWpsPPT;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.judgementVO.JudgementReqVo;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideConversion;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.SlideMaster;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.SlideDataInfoVO;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.vo.PptxInfoReqVo;
|
||||
@@ -32,7 +33,7 @@ public class JudgementWpsPptxServiceImpl implements JudgementWpsPptxService {
|
||||
|
||||
@Override
|
||||
public List<JudgementSlidesVO> slideMaster(List<WpsSlideInfoVo> wpsSlideInfoVos, MultipartFile file) throws Exception {
|
||||
return List.of();
|
||||
return SlideMaster.slideMaster(file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,54 @@
|
||||
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
|
||||
|
||||
import org.docx4j.dml.chartDrawing.CTShape;
|
||||
import org.docx4j.openpackaging.exceptions.Docx4JException;
|
||||
import org.docx4j.openpackaging.packages.OpcPackage;
|
||||
import org.docx4j.openpackaging.packages.PresentationMLPackage;
|
||||
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
|
||||
import org.pptx4j.pml.GroupShape;
|
||||
import org.pptx4j.pml.Presentation;
|
||||
import org.pptx4j.pml.Shape;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.vo.JudgementSlidesVO;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SlideMaster {
|
||||
|
||||
public static List<JudgementSlidesVO> slideMaster(MultipartFile file) throws IOException, Docx4JException {
|
||||
List<JudgementSlidesVO> judgementSlidesVOS = new ArrayList<>();
|
||||
// 1、获取想要判断的文件地址(文件流)
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
// 加载 .pptx 文件
|
||||
PresentationMLPackage ppt =
|
||||
(PresentationMLPackage) OpcPackage.load(inputStream);
|
||||
|
||||
// 你可以在这里处理 ppt,比如读取文字、页数等
|
||||
List<SlidePart> slideParts = ppt.getMainPresentationPart().getSlideParts();
|
||||
int slideIndex = 1;
|
||||
for (SlidePart slidePart : slideParts) {
|
||||
// 获取幻灯片内容
|
||||
System.out.println("========== 幻灯片 " + slideIndex++ + " ==========");
|
||||
// 遍历 shape tree 中的 sp(shape)元素
|
||||
GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree();
|
||||
List<Object> shapes = spTree.getSpOrGrpSpOrGraphicFrame();
|
||||
for (Object shapeObj : shapes) {
|
||||
if (shapeObj instanceof Shape) {
|
||||
Shape shape = (Shape) shapeObj;
|
||||
System.out.println("Shape name: " + shape.getNvSpPr().getCNvPr().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return judgementSlidesVOS;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user