临时提交

This commit is contained in:
chenxudong 2025-02-17 15:49:45 +08:00
parent c6758de47a
commit 3c8d8b165e
2 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package com.electromagnetic.industry.software.common.parse;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.IdUtil;
import java.io.File;
@ -12,7 +13,7 @@ public abstract class FileParse {
public abstract String parseAllText(InputStream stream, String fileType);
protected String createFileTmpPath(String fileType) {
String uuid = IdUtil.fastSimpleUUID();
return tmpPath + File.separator + uuid + "." + fileType;
tmpPath = FileUtil.getParent(tmpPath, 3) + File.separator + "tmp" + File.separator + IdUtil.simpleUUID() + "." + fileType;
return tmpPath;
}
}

View File

@ -34,6 +34,7 @@ import java.util.Objects;
public class OfficeFileUtil {
public static void doc2pdf(String wordPath, String pdfPath) {
log.info("Start convert word file to pdf, word path: {}, pdf path: {}", wordPath, pdfPath);
if (EleCommonUtil.isWinOs()) {
File inputWord = new File(wordPath);
File outputFile = new File(pdfPath);
@ -76,6 +77,7 @@ public class OfficeFileUtil {
}
public static String parseDocxAllText(String wordPath) throws IOException {
log.info("Start parse docx file, path is {}", wordPath);
InputStream fis = Files.newInputStream(Paths.get(wordPath));
XWPFDocument document = new XWPFDocument();
StringBuilder stringBuilder = new StringBuilder();
@ -89,6 +91,7 @@ public class OfficeFileUtil {
}
public static String parsePdfAllText(String path) throws IOException {
log.info("Start parse pdf file, path is {}", path);
// 加载PDF文档
PDDocument document = PDDocument.load(new File(path));
// 创建PDFTextStripper对象来解析文本
@ -100,6 +103,7 @@ public class OfficeFileUtil {
}
public static String parseDocAllText(String path) throws IOException {
log.info("Start parse doc file, path is {}", path);
FileInputStream fis = new FileInputStream(path);
HWPFDocument document = new HWPFDocument(fis);
WordExtractor wordExtractor = new WordExtractor(document);
@ -113,6 +117,7 @@ public class OfficeFileUtil {
}
public static String parseXlsxAllText(String path) throws IOException {
log.info("Start parse xlsx file, path is {}", path);
XSSFWorkbook excel = new XSSFWorkbook(FileUtil.getInputStream(path));
int activeSheetIndex = excel.getNumberOfSheets();
StringBuilder stringBuilder = new StringBuilder();
@ -133,6 +138,7 @@ public class OfficeFileUtil {
}
public static String parseXlsAllText(String path) throws IOException {
log.info("Start parse xls file, path is {}", path);
Workbook sheets = WorkbookFactory.create(FileUtil.getInputStream(path));
int numberOfSheets = sheets.getNumberOfSheets();
StringBuilder stringBuilder = new StringBuilder();