|
@@ -14,9 +14,11 @@ import lombok.SneakyThrows;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.http.util.TextUtils;
|
|
import org.apache.http.util.TextUtils;
|
|
import org.apache.poi.hwpf.HWPFDocument;
|
|
import org.apache.poi.hwpf.HWPFDocument;
|
|
|
|
+import org.apache.poi.hwpf.extractor.WordExtractor;
|
|
import org.apache.poi.hwpf.usermodel.Range;
|
|
import org.apache.poi.hwpf.usermodel.Range;
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFRun;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -162,24 +164,24 @@ public class OSSService {
|
|
ByteArrayInputStream fis = new ByteArrayInputStream(IoUtil.readBytes(file.getInputStream()));
|
|
ByteArrayInputStream fis = new ByteArrayInputStream(IoUtil.readBytes(file.getInputStream()));
|
|
|
|
|
|
HWPFDocument document = new HWPFDocument(fis);
|
|
HWPFDocument document = new HWPFDocument(fis);
|
|
- Range range = document.getRange();
|
|
|
|
|
|
|
|
- // 创建一个新的空白docx文档
|
|
|
|
- XWPFDocument newDocument = new XWPFDocument();
|
|
|
|
-
|
|
|
|
- // 遍历原始doc文件的段落并添加到新的docx文档中
|
|
|
|
- for (int i = 0; i < range.numParagraphs(); i++) {
|
|
|
|
- XWPFParagraph paragraph = newDocument.createParagraph();
|
|
|
|
- paragraph.createRun().setText(range.getParagraph(i).text());
|
|
|
|
- }
|
|
|
|
|
|
+ WordExtractor wordExtractor = new WordExtractor(document);
|
|
|
|
+ String text = wordExtractor.getText();
|
|
|
|
+ XWPFDocument xwpfDocument = new XWPFDocument();
|
|
|
|
+ XWPFParagraph paragraph = xwpfDocument.createParagraph();
|
|
|
|
+ XWPFRun run = paragraph.createRun();
|
|
|
|
+ run.setText(text);
|
|
|
|
+ ByteArrayOutputStream fos = new ByteArrayOutputStream();
|
|
|
|
+ xwpfDocument.write(fos);
|
|
|
|
|
|
String dir = "open/bid/" + id + "/";
|
|
String dir = "open/bid/" + id + "/";
|
|
String fileUrl = dir + file.getOriginalFilename() + "x";
|
|
String fileUrl = dir + file.getOriginalFilename() + "x";
|
|
- ossClient.putObject(bucket, fileUrl , newDocument.getDocument().newInputStream());
|
|
|
|
|
|
+ ossClient.putObject(bucket, fileUrl , xwpfDocument.getDocument().newInputStream());
|
|
fis.reset();
|
|
fis.reset();
|
|
|
|
|
|
String encodedString = URLEncoder.encode(fileUrl, StandardCharsets.UTF_8);
|
|
String encodedString = URLEncoder.encode(fileUrl, StandardCharsets.UTF_8);
|
|
- newDocument.close();
|
|
|
|
|
|
+ document.close();
|
|
|
|
+ xwpfDocument.close();
|
|
|
|
|
|
return "https://cxzx.smcic.net/" + encodedString;
|
|
return "https://cxzx.smcic.net/" + encodedString;
|
|
}
|
|
}
|