update 文档拆分处理上下标
This commit is contained in:
+29
-17
@@ -147,9 +147,9 @@ public class FileSpiltService {
|
||||
throw new JeroBootException("当前文件未找到,请重新选择!");
|
||||
}
|
||||
|
||||
try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
|
||||
//readFilePath = "E:\\Data\\Downloads\\wordtest\\GB7258标准修订test.docx";
|
||||
//try (InputStream is = new FileInputStream(readFilePath);InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
|
||||
//try (InputStream is = MinioUtil.download(readFilePath);InputStream is1 = MinioUtil.download(readFilePath)) {
|
||||
readFilePath = "E:\\Data\\Downloads\\wordtest\\GB7258标准修订test - 表格测试 - 副本.docx";
|
||||
try (InputStream is = new FileInputStream(readFilePath);InputStream is1 = new FileInputStream(readFilePath)) {//需要将文件路更改为word文档所在路径。
|
||||
ZipSecureFile.setMinInflateRatio(-1.0d);
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
|
||||
@@ -177,9 +177,28 @@ public class FileSpiltService {
|
||||
// 段落
|
||||
if (element instanceof XWPFParagraph) {
|
||||
XWPFParagraph p = (XWPFParagraph) element;
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (XWPFRun xwrun : p.getRuns()) {
|
||||
VerticalAlign subscript = xwrun.getSubscript();
|
||||
String smalltext = xwrun.getText(0);
|
||||
switch (subscript) {
|
||||
case BASELINE:
|
||||
stringBuilder.append(smalltext);
|
||||
break;
|
||||
case SUBSCRIPT:
|
||||
System.out.println("smalltext, subscript = " + smalltext);
|
||||
stringBuilder.append("<sub>").append(smalltext).append("</sub>");
|
||||
break;
|
||||
case SUPERSCRIPT:
|
||||
System.out.println("smalltext, superscript = " + smalltext);
|
||||
stringBuilder.append("<sup>").append(smalltext).append("</sup>");
|
||||
break;
|
||||
default:
|
||||
stringBuilder.append(smalltext);
|
||||
}
|
||||
}
|
||||
// 处理段落生成编号不识别问题
|
||||
String paragraphString = p.getText();
|
||||
String paragraphString = stringBuilder.toString();
|
||||
if (StringUtils.isNotBlank(paragraphString)) {
|
||||
paragraphString = paragraphString.replace((char) 12288, ' ');
|
||||
paragraphString = paragraphString.trim();
|
||||
@@ -227,14 +246,14 @@ public class FileSpiltService {
|
||||
Integer numbernow = (Integer) numberMap.get(numberParent) + 1;
|
||||
if (messageList != null && !messageList.isEmpty() && messageList.get(messageList.size() - 1).getItemsNum().equals(numberParent + "." + String.valueOf(numbernow))) {
|
||||
numberMap.put(numberParent, numbernow + 1);
|
||||
paragraphString = numberParent + "." + String.valueOf(numbernow + 1) + p.getText();
|
||||
paragraphString = numberParent + "." + String.valueOf(numbernow + 1) + paragraphString;
|
||||
} else {
|
||||
numberMap.put(numberParent, numbernow);
|
||||
paragraphString = numberParent + "." + String.valueOf(numbernow) + p.getText();
|
||||
paragraphString = numberParent + "." + String.valueOf(numbernow) + paragraphString;
|
||||
}
|
||||
} else {
|
||||
numberMap.put(numberParent, 1);
|
||||
paragraphString = numberParent + ".1" + p.getText();
|
||||
paragraphString = numberParent + ".1" + paragraphString;
|
||||
}
|
||||
}
|
||||
if (messageNumber == 0) {
|
||||
@@ -291,9 +310,6 @@ public class FileSpiltService {
|
||||
}else {
|
||||
startDigit = getOneStartDigit(paragraphString, enumByValue);
|
||||
}
|
||||
if (startDigit.equals("15.8")){
|
||||
ptest = Pattern.compile("^[\\d.]*$");
|
||||
}
|
||||
for (int i = 0; i < nowStart.size(); i++) {
|
||||
// if (paragraphString.startsWith(nowStart.get(i))) {
|
||||
if (startDigit.equals(nowStart.get(i))) {
|
||||
@@ -335,10 +351,6 @@ public class FileSpiltService {
|
||||
// 判断是否是附录
|
||||
ptest = Pattern.compile("^附录\\s{0,3}[A-Z]{1}");
|
||||
matcher = ptest.matcher(paragraphString);
|
||||
String title = "";
|
||||
if (StringUtils.isNotBlank(paragraphString) && titleNumberMap.containsKey(paragraphString)){
|
||||
title = titleNumberMap.get(paragraphString);
|
||||
}
|
||||
// 获取当前最后一项num
|
||||
String appendixNum = messageList.get(messageList.size() - 1).getItemsNum().split("\\.")[0];
|
||||
if (matcher.find()&& !messageList.get(messageList.size() - 1).getItemsNum().equals("附录")) {
|
||||
@@ -358,8 +370,8 @@ public class FileSpiltService {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!p.getText().equals("")) {
|
||||
addItermsConditionsText(messageList.get(messageList.size() - 1), itemValList, p.getText());
|
||||
if (!paragraphString.equals("")) {
|
||||
addItermsConditionsText(messageList.get(messageList.size() - 1), itemValList, paragraphString);
|
||||
}
|
||||
List<String> imageBundleList = readImageInParagraph((XWPFParagraph) p);
|
||||
if (CollectionUtils.isNotEmpty(imageBundleList)) {
|
||||
|
||||
Reference in New Issue
Block a user