临时提交
This commit is contained in:
parent
c6758de47a
commit
3c8d8b165e
|
|
@ -1,5 +1,6 @@
|
||||||
package com.electromagnetic.industry.software.common.parse;
|
package com.electromagnetic.industry.software.common.parse;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -12,7 +13,7 @@ public abstract class FileParse {
|
||||||
public abstract String parseAllText(InputStream stream, String fileType);
|
public abstract String parseAllText(InputStream stream, String fileType);
|
||||||
|
|
||||||
protected String createFileTmpPath(String fileType) {
|
protected String createFileTmpPath(String fileType) {
|
||||||
String uuid = IdUtil.fastSimpleUUID();
|
tmpPath = FileUtil.getParent(tmpPath, 3) + File.separator + "tmp" + File.separator + IdUtil.simpleUUID() + "." + fileType;
|
||||||
return tmpPath + File.separator + uuid + "." + fileType;
|
return tmpPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import java.util.Objects;
|
||||||
public class OfficeFileUtil {
|
public class OfficeFileUtil {
|
||||||
|
|
||||||
public static void doc2pdf(String wordPath, String pdfPath) {
|
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()) {
|
if (EleCommonUtil.isWinOs()) {
|
||||||
File inputWord = new File(wordPath);
|
File inputWord = new File(wordPath);
|
||||||
File outputFile = new File(pdfPath);
|
File outputFile = new File(pdfPath);
|
||||||
|
|
@ -76,6 +77,7 @@ public class OfficeFileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseDocxAllText(String wordPath) throws IOException {
|
public static String parseDocxAllText(String wordPath) throws IOException {
|
||||||
|
log.info("Start parse docx file, path is {}", wordPath);
|
||||||
InputStream fis = Files.newInputStream(Paths.get(wordPath));
|
InputStream fis = Files.newInputStream(Paths.get(wordPath));
|
||||||
XWPFDocument document = new XWPFDocument();
|
XWPFDocument document = new XWPFDocument();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
@ -89,6 +91,7 @@ public class OfficeFileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parsePdfAllText(String path) throws IOException {
|
public static String parsePdfAllText(String path) throws IOException {
|
||||||
|
log.info("Start parse pdf file, path is {}", path);
|
||||||
// 加载PDF文档
|
// 加载PDF文档
|
||||||
PDDocument document = PDDocument.load(new File(path));
|
PDDocument document = PDDocument.load(new File(path));
|
||||||
// 创建PDFTextStripper对象来解析文本
|
// 创建PDFTextStripper对象来解析文本
|
||||||
|
|
@ -100,6 +103,7 @@ public class OfficeFileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseDocAllText(String path) throws IOException {
|
public static String parseDocAllText(String path) throws IOException {
|
||||||
|
log.info("Start parse doc file, path is {}", path);
|
||||||
FileInputStream fis = new FileInputStream(path);
|
FileInputStream fis = new FileInputStream(path);
|
||||||
HWPFDocument document = new HWPFDocument(fis);
|
HWPFDocument document = new HWPFDocument(fis);
|
||||||
WordExtractor wordExtractor = new WordExtractor(document);
|
WordExtractor wordExtractor = new WordExtractor(document);
|
||||||
|
|
@ -113,6 +117,7 @@ public class OfficeFileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseXlsxAllText(String path) throws IOException {
|
public static String parseXlsxAllText(String path) throws IOException {
|
||||||
|
log.info("Start parse xlsx file, path is {}", path);
|
||||||
XSSFWorkbook excel = new XSSFWorkbook(FileUtil.getInputStream(path));
|
XSSFWorkbook excel = new XSSFWorkbook(FileUtil.getInputStream(path));
|
||||||
int activeSheetIndex = excel.getNumberOfSheets();
|
int activeSheetIndex = excel.getNumberOfSheets();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
@ -133,6 +138,7 @@ public class OfficeFileUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String parseXlsAllText(String path) throws IOException {
|
public static String parseXlsAllText(String path) throws IOException {
|
||||||
|
log.info("Start parse xls file, path is {}", path);
|
||||||
Workbook sheets = WorkbookFactory.create(FileUtil.getInputStream(path));
|
Workbook sheets = WorkbookFactory.create(FileUtil.getInputStream(path));
|
||||||
int numberOfSheets = sheets.getNumberOfSheets();
|
int numberOfSheets = sheets.getNumberOfSheets();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue