update 文档拆分处理表格中的公式
This commit is contained in:
+51
-156
@@ -241,45 +241,14 @@ public class FileSpiltService {
|
|||||||
if (element instanceof XWPFParagraph) {
|
if (element instanceof XWPFParagraph) {
|
||||||
XWPFParagraph p = (XWPFParagraph) element;
|
XWPFParagraph p = (XWPFParagraph) element;
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
//读取公式
|
||||||
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(p);
|
if (messageList.size() > 0) {
|
||||||
List<Object> childList = runOrMaths.getChildList();
|
List<String> mathInParagraph = readMathInParagraph(p);
|
||||||
for (Object child : childList) {
|
for (String post : mathInParagraph) {
|
||||||
//if (child instanceof XWPFRun) {
|
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
|
||||||
// //处理段落中的文本以及图片
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (XWPFRun xwrun : p.getRuns()) {
|
for (XWPFRun xwrun : p.getRuns()) {
|
||||||
VerticalAlign subscript = xwrun.getSubscript();
|
VerticalAlign subscript = xwrun.getSubscript();
|
||||||
String smalltext = xwrun.getText(0);
|
String smalltext = xwrun.getText(0);
|
||||||
@@ -753,92 +722,31 @@ public class FileSpiltService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<String> readMathInParagraph(XWPFParagraph paragraph) {
|
private List<String> readMathInParagraph(XWPFParagraph paragraph) {
|
||||||
//图片索引List
|
//公式图片地址List
|
||||||
List<String> imageBundleList = new ArrayList<String>();
|
List<String> mathPicNameList = new ArrayList<>();
|
||||||
|
//获取公式
|
||||||
//段落中所有XWPFRun
|
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager(paragraph);
|
||||||
List<XWPFRun> runList = paragraph.getRuns();
|
List<Object> childList = runOrMaths.getChildList();
|
||||||
StringBuffer text = new StringBuffer();
|
for (Object child : childList) {
|
||||||
for (XWPFRun run : runList) {
|
String xmlText = null;
|
||||||
Node runNode = run.getCTR().getDomNode();
|
if (child instanceof CTOMath) {
|
||||||
text.append(getText(runNode));
|
CTOMath ctoMath = (CTOMath) child;
|
||||||
|
xmlText = ctoMath.xmlText().replaceAll("xml-fragment","m:oMath");
|
||||||
String math = getMath(run, runNode);
|
}
|
||||||
text.append(math);
|
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 mathPicNameList;
|
||||||
return imageBundleList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取字符串
|
|
||||||
*
|
|
||||||
* @param runNode
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String getText(Node runNode) {
|
|
||||||
Node textNode = getChildNode(runNode, "w:t");
|
|
||||||
if (textNode == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return textNode.getFirstChild().getNodeValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getMath(XWPFRun run, Node runNode) {
|
|
||||||
Node objectNode = getChildNode(runNode, "m:oMathPara");
|
|
||||||
if (objectNode == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Node shapeNode = getChildNode(objectNode, "v:shape");
|
|
||||||
if (shapeNode == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Node imageNode = getChildNode(shapeNode, "v:imagedata");
|
|
||||||
if (imageNode == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
Node binNode = getChildNode(objectNode, "o:OLEObject");
|
|
||||||
if (binNode == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
XWPFDocument word = run.getDocument();
|
|
||||||
|
|
||||||
NamedNodeMap shapeAttrs = shapeNode.getAttributes();
|
|
||||||
// 图片在Word中显示的宽高
|
|
||||||
String style = shapeAttrs.getNamedItem("style").getNodeValue();
|
|
||||||
System.out.println("图片宽高:".concat(style));
|
|
||||||
|
|
||||||
System.out.println("--------------");
|
|
||||||
|
|
||||||
NamedNodeMap imageAttrs = imageNode.getAttributes();
|
|
||||||
// 图片在Word中的ID
|
|
||||||
String imageRid = imageAttrs.getNamedItem("r:id").getNodeValue();
|
|
||||||
// 获取图片信息
|
|
||||||
PackagePart imgPart = word.getPartById(imageRid);
|
|
||||||
System.out.println("图片名称".concat(imgPart.getPartName().getName()));
|
|
||||||
try {
|
|
||||||
System.out.println(imgPart.getInputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("--------------");
|
|
||||||
|
|
||||||
NamedNodeMap binAttrs = binNode.getAttributes();
|
|
||||||
// 公式二进制文件在Word中的ID
|
|
||||||
String binRid = binAttrs.getNamedItem("r:id").getNodeValue();
|
|
||||||
// 获取二进制文件
|
|
||||||
PackagePart binPart = word.getPartById(binRid);
|
|
||||||
System.out.println("二进制文件名称:".concat(binPart.getPartName().getName()));
|
|
||||||
try {
|
|
||||||
System.out.println(binPart.getInputStream());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println("--------------");
|
|
||||||
|
|
||||||
return "{公式#}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getChildNode(Node node, String nodeName) {
|
private Node getChildNode(Node node, String nodeName) {
|
||||||
@@ -936,6 +844,13 @@ public class FileSpiltService {
|
|||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
|
List<XWPFParagraph> paragraphs = tableCell.getParagraphs();
|
||||||
for (XWPFParagraph paragraph : paragraphs) {
|
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);
|
List<String> imageBundleList = readImageInParagraph(paragraph);
|
||||||
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
||||||
String s = addTableImage(paragraph, imageBundleList);
|
String s = addTableImage(paragraph, imageBundleList);
|
||||||
@@ -988,6 +903,16 @@ public class FileSpiltService {
|
|||||||
itemsValList.add(getSplitItemsValObject(message.getId(), SplitFilePragraTypeEnum.IMG.getValue(), path, message.getItemsCondi().size(), null));
|
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) {
|
private void addItermsConditionsImage(SarFileSplitItemsEO message, List<SarFileSplitItemsValEO> itemsValList, XWPFParagraph p, List<String> imageBundleList) {
|
||||||
for (String pictureId : imageBundleList) {
|
for (String pictureId : imageBundleList) {
|
||||||
@@ -1233,41 +1158,11 @@ public class FileSpiltService {
|
|||||||
XWPFParagraph p = (XWPFParagraph) element;
|
XWPFParagraph p = (XWPFParagraph) element;
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
//读取公式
|
||||||
ParagraphChildOrderManager runOrMaths = new ParagraphChildOrderManager((XWPFParagraph) element);
|
if (messageList.size() > 0) {
|
||||||
List<Object> childList = runOrMaths.getChildList();
|
List<String> mathInParagraph = readMathInParagraph(p);
|
||||||
for (Object child : childList) {
|
for (String post : mathInParagraph) {
|
||||||
//if (child instanceof XWPFRun) {
|
addItermsMathImage(messageList.get(messageList.size() - 1), itemValList, post);
|
||||||
// //处理段落中的文本以及图片
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user