队友合代码的时候用她的电脑生成PPT功能会报500错误,说layout为空,加入判断是否为空的逻辑后导致结尾页识别不了了,参看日志发现可能是直接按照内容页判断的,判断不出就自行创建了一页幻灯片,这样显然是不对的。
2024-06-16T13:06:42.528+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 标题
2024-06-16T13:06:42.528+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '标题' with '探索粉色花朵的美丽'
2024-06-16T13:06:42.529+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 副标题
2024-06-16T13:06:42.529+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 探索粉色花朵的美丽
2024-06-16T13:06:42.529+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 副标题
2024-06-16T13:06:42.529+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '副标题' with '从自然到艺术的粉色花卉之旅'
2024-06-16T13:06:42.529+08:00 INFO 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Inserting cover picture from generated image
2024-06-16T13:06:42.659+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 目录
2024-06-16T13:06:42.660+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '目录' with '目录'
2024-06-16T13:06:42.660+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 目录内容
2024-06-16T13:06:42.660+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 目录
2024-06-16T13:06:42.660+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 目录内容
2024-06-16T13:06:42.660+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '目录内容' with '简介:粉色花朵的魅力
粉色花朵的种类:不同品种的介绍
粉色花朵在艺术中的运用
如何种植和护理粉色花朵'
2024-06-16T13:06:42.661+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 主题
2024-06-16T13:06:42.662+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '主题' with '简介'
2024-06-16T13:06:42.662+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.662+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 简介
2024-06-16T13:06:42.662+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.662+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '内容' with '粉色花朵象征着温柔、爱和美丽,在自然界和艺术中都占有重要的地位。'
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 主题
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '主题' with '粉色花朵的种类'
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 粉色花朵的种类
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.663+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '内容' with '介绍不同品种的粉色花朵,例如玫瑰、樱花、牡丹等。'
2024-06-16T13:06:42.664+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 主题
2024-06-16T13:06:42.664+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '主题' with '粉色花朵在艺术中的运用'
2024-06-16T13:06:42.664+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.665+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 粉色花朵在艺术中的运用
2024-06-16T13:06:42.665+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 内容
2024-06-16T13:06:42.665+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Replaced '内容' with '探讨粉色花朵在绘画、摄影、园艺设计中的运用。'
2024-06-16T13:06:42.665+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 结尾内容
2024-06-16T13:06:42.665+08:00 WARN 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Placeholder '主题' not found in the slide.
2024-06-16T13:06:42.665+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 结尾内容
2024-06-16T13:06:42.665+08:00 WARN 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Placeholder '内容' not found in the slide.
2024-06-16T13:06:42.666+08:00 WARN 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Layout 'title_and_content' not found. Using default layout.
2024-06-16T13:06:42.666+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptTemplateService : Default layout found: 比较
2024-06-16T13:06:42.682+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Handling ending slide with content: 感谢各位的参与和关注。
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 单击此处编辑母版标题样式
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 单击此处编辑母版文本样式
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 单击此处编辑母版文本样式
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 二级
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 三级
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 四级
2024-06-16T13:06:42.683+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 五级
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 单击此处编辑母版文本样式
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 单击此处编辑母版文本样式
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 二级
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 三级
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 四级
2024-06-16T13:06:42.684+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Checking text in slide: 五级
2024-06-16T13:06:42.684+08:00 WARN 6172 --- [PPT_project_backend] [nio-8080-exec-2] c.e.p.service.PptOperationService : Placeholder '结尾内容' not found in the slide.
2024-06-16T13:06:42.725+08:00 DEBUG 6172 --- [PPT_project_backend] [nio-8080-exec-2] o.apache.poi.openxml4j.opc.ZipPackage : Save content types part
很奇怪,之前没加判断逻辑的时候是能正常识别结尾页并加入内容的。
找到原因,是因为模板PPT中“内容页”数量少于传入参数中的内容页数量,加入逻辑,判断应该复制的幻灯片和幻灯片页数。
// 获取模板中的内容页
Optional<XSLFSlide> optionalContentSlide = ppt.getSlides().stream()
.filter(this::isContentSlide)
.findFirst();
if (!optionalContentSlide.isPresent()) {
throw new IllegalArgumentException("Template does not contain a content slide with text '主题'");
}
XSLFSlide contentSlideTemplate = optionalContentSlide.get();
XSLFSlideLayout contentLayout = contentSlideTemplate.getSlideLayout();
// 计算模板中已有的内容页数量
int templateContentSlideCount = (int) ppt.getSlides().stream()
.filter(this::isContentSlide)
.count();
// 计算所需的内容页数量
long requiredContentSlides = slides.stream().filter(s -> s.getTitle().equals("内容页")).count();
// 如果所需内容页数量大于模板中的内容页数量,复制内容页
if (requiredContentSlides > templateContentSlideCount) {
int slidesToAdd = (int) requiredContentSlides - templateContentSlideCount;
for (int i = 0; i < slidesToAdd; i++) {
ppt.createSlide(contentLayout);
}
}
标签:11,project,00,06,08,2024,实训,PPT
From: https://blog.csdn.net/m0_64226812/article/details/139719246