fix 表格中的公式没有拆分出来
This commit is contained in:
+46
-48
@@ -212,40 +212,11 @@ public class FileSpiltService {
|
||||
XWPFParagraph p = (XWPFParagraph) element;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(p);
|
||||
List<Object> childList = runOrMaths.getChildList();
|
||||
|
||||
for (Object child : childList) {
|
||||
//if (child instanceof XWPFRun) {
|
||||
// //处理段落中的文本以及图片
|
||||
// handleParagraphRun(content, (XWPFRun) child, imageParser);
|
||||
//} else
|
||||
if (child instanceof CTOMath) {
|
||||
CTOMath ctoMath = (CTOMath) child;
|
||||
String xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("encode", xmlText);
|
||||
String post = HttpRequest.post(mathToImgUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(xmlText)
|
||||
.execute().body();
|
||||
//String post = HttpUtil.post(mathToImgUrl, map);
|
||||
if (messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
|
||||
}
|
||||
} else if (child instanceof CTOMathPara) {
|
||||
CTOMathPara ctoMathPara = (CTOMathPara) child;
|
||||
String xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");;
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("encode",xmlText);
|
||||
String post = HttpRequest.post(mathToImgUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(xmlText)
|
||||
.execute().body();
|
||||
//String post = HttpUtil.post(mathToImgUrl, map);
|
||||
if (messageList.size() > 0) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
|
||||
}
|
||||
//读取公式
|
||||
if (messageList.size() > 0) {
|
||||
List<String> mathInParagraph = readMathInParagraph(p);
|
||||
for (String post : mathInParagraph) {
|
||||
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -756,21 +727,31 @@ public class FileSpiltService {
|
||||
}
|
||||
|
||||
private List<String> readMathInParagraph(XWPFParagraph paragraph) {
|
||||
//图片索引List
|
||||
List<String> imageBundleList = new ArrayList<String>();
|
||||
|
||||
//段落中所有XWPFRun
|
||||
List<XWPFRun> runList = paragraph.getRuns();
|
||||
StringBuffer text = new StringBuffer();
|
||||
for (XWPFRun run : runList) {
|
||||
Node runNode = run.getCTR().getDomNode();
|
||||
text.append(getText(runNode));
|
||||
|
||||
String math = getMath(run, runNode);
|
||||
text.append(math);
|
||||
//公式图片地址List
|
||||
List<String> mathPicNameList = new ArrayList<>();
|
||||
//获取公式
|
||||
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(paragraph);
|
||||
List<Object> childList = runOrMaths.getChildList();
|
||||
for (Object child : childList) {
|
||||
String xmlText = null;
|
||||
if (child instanceof CTOMath) {
|
||||
CTOMath ctoMath = (CTOMath) child;
|
||||
xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
|
||||
}
|
||||
else if (child instanceof CTOMathPara) {
|
||||
CTOMathPara ctoMathPara = (CTOMathPara) child;
|
||||
xmlText = ctoMathPara.xmlText().replaceAll("xml-fragment","m:oMath");;
|
||||
}
|
||||
if (xmlText != null){
|
||||
//生成图片
|
||||
String post = HttpRequest.post(mathToImgUrl)
|
||||
.header(Header.CONTENT_TYPE, "application/json")
|
||||
.body(xmlText)
|
||||
.execute().body();
|
||||
mathPicNameList.add(post);
|
||||
}
|
||||
}
|
||||
System.out.println("段落内容:".concat(text.toString()));
|
||||
return imageBundleList;
|
||||
return mathPicNameList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -939,6 +920,13 @@ public class FileSpiltService {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
|
||||
for (XWPFParagraph paragraph : paragraphs) {
|
||||
List<String> mathInParagraph = readMathInParagraph(paragraph);
|
||||
if (CollectionUtils.isNotEmpty(mathInParagraph)) {
|
||||
String s = addTableMath(mathInParagraph);
|
||||
stringBuilder.append(s);
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> imageBundleList = readImageInParagraph(paragraph);
|
||||
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
||||
String s = addTableImage(paragraph, imageBundleList);
|
||||
@@ -991,6 +979,16 @@ public class FileSpiltService {
|
||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.IMG.getValue(), path, message.getItemsCondi().size(), null));
|
||||
}
|
||||
|
||||
public String addTableMath(List<String> imageBundleList){
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String imageName : imageBundleList) {
|
||||
String path = splitUrl + imageName;
|
||||
String imgConVal = "<img class=\"wordImg\" style=\"width:100%;height:100%\" src=\"" + path + "\">";
|
||||
stringBuilder.append(imgConVal);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
// 像每个条款中依次插入每一段的内容
|
||||
private void addItermsConditionsImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFParagraph p, List<String> imageBundleList) {
|
||||
for (String pictureId : imageBundleList) {
|
||||
|
||||
Reference in New Issue
Block a user