调通了ppt文件解析

This commit is contained in:
chenxudong 2025-02-18 10:08:44 +08:00
parent f9a9fee343
commit 6c1e024d51
2 changed files with 4 additions and 5 deletions

View File

@ -15,10 +15,7 @@ public class PptParse extends FileParse {
String res = ""; String res = "";
try { try {
FileUtil.writeFromStream(stream, fileTmpPath); FileUtil.writeFromStream(stream, fileTmpPath);
if (fileType.endsWith("pptx")) { res = fileType.endsWith("pptx") ? OfficeFileUtil.parsePptxAllText(fileTmpPath) : OfficeFileUtil.parsePptAllText(fileTmpPath);
res = OfficeFileUtil.parsePptxAllText(fileTmpPath);
}
res = OfficeFileUtil.parsePptAllText(fileTmpPath);
} catch (Exception e) { } catch (Exception e) {
log.error("解析{}格式的ppt错误具体为{}",fileType, e.getMessage(), e); log.error("解析{}格式的ppt错误具体为{}",fileType, e.getMessage(), e);
} }

View File

@ -175,17 +175,19 @@ public class OfficeFileUtil {
} }
public static String parsePptAllText(String filePath) throws IOException { public static String parsePptAllText(String filePath) throws IOException {
log.info("Start parse ppt file, path is {}", filePath);
return handlePptFile(filePath, false); return handlePptFile(filePath, false);
} }
public static String parsePptxAllText(String filePath) throws IOException { public static String parsePptxAllText(String filePath) throws IOException {
log.info("Start parse pptx file, path is {}", filePath);
return handlePptFile(filePath, true); return handlePptFile(filePath, true);
} }
private static String handlePptFile(String path, boolean isPptx) throws IOException { private static String handlePptFile(String path, boolean isPptx) throws IOException {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
InputStream input = Files.newInputStream(Paths.get(path)); InputStream input = Files.newInputStream(Paths.get(path));
String pptText = isPptx ? new SlideShowExtractor(new HSLFSlideShow(input)).getText() : new SlideShowExtractor(new XMLSlideShow(input)).getText(); String pptText = isPptx ? new SlideShowExtractor(new XMLSlideShow(input)).getText() : new SlideShowExtractor(new HSLFSlideShow(input)).getText();
stringBuilder.append(pptText); stringBuilder.append(pptText);
return EleCommonUtil.formateString(stringBuilder.toString()); return EleCommonUtil.formateString(stringBuilder.toString());
} }