修改文档自动生成序号不识别问题
This commit is contained in:
@@ -4,12 +4,12 @@ import com.aspose.words.*;
|
||||
import com.jero.modules.split.vo.TitleNumberVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.poi.xwpf.usermodel.VerticalAlign;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author liJiaRao
|
||||
@@ -23,28 +23,19 @@ public class AsposeUtil {
|
||||
* @return
|
||||
*/
|
||||
public static TitleNumberVO getNumber(InputStream is) {
|
||||
long time1=System.currentTimeMillis();
|
||||
|
||||
TitleNumberVO titleNumberVO = new TitleNumberVO();
|
||||
Map<String, List<String>> titleNumberMap = new HashMap<>();
|
||||
List<String> emptyTitleList = new ArrayList<>();
|
||||
List<String> titleNumberList = new ArrayList<>();
|
||||
try {
|
||||
long time9=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time9-time1)+"ms");
|
||||
Document doc = new Document(is);
|
||||
long time8=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time8-time1)+"ms");
|
||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||
long time7=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time7-time1)+"ms");
|
||||
//builder.insertField(FieldType.FIELD_NUM_PAGES, true);
|
||||
long time6=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time6-time1)+"ms");
|
||||
//获取段落
|
||||
NodeCollection childNodes = doc.getChildNodes(NodeType.PARAGRAPH, true);
|
||||
|
||||
long time2=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time2-time1)+"ms");
|
||||
DocumentBuilder builder = new DocumentBuilder(doc);
|
||||
|
||||
builder.insertField(FieldType.FIELD_NUM_PAGES, true);
|
||||
//获取段落
|
||||
NodeCollection childNodes = doc.getChildNodes(NodeType.ANY, true);
|
||||
|
||||
for (int i = 0; i < childNodes.getCount(); i++) {
|
||||
Node next = childNodes.get(i);
|
||||
|
||||
@@ -68,7 +59,9 @@ public class AsposeUtil {
|
||||
labelString = listLabel.getLabelString().trim();
|
||||
labelString = labelString.replaceAll("\t", "").replaceAll("\b", "")
|
||||
.replaceAll(" ", "").replaceAll("\"", "").replaceAll("'", "").replaceAll(" ", "");
|
||||
|
||||
if (StringUtils.isBlank(labelString)){
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
if (titleNumberMap.containsKey(text)) {
|
||||
List<String> strings = titleNumberMap.get(text);
|
||||
@@ -78,6 +71,7 @@ public class AsposeUtil {
|
||||
strings.add(labelString);
|
||||
titleNumberMap.put(text, strings);
|
||||
}
|
||||
titleNumberList.add(labelString);
|
||||
} else {
|
||||
emptyTitleList.add(labelString);
|
||||
}
|
||||
@@ -88,14 +82,8 @@ public class AsposeUtil {
|
||||
e.printStackTrace();
|
||||
}
|
||||
titleNumberVO.setTitleNumberMap(titleNumberMap);
|
||||
emptyTitleList.removeIf(titleNumberList::contains);
|
||||
titleNumberVO.setEmptyTitleList(emptyTitleList);
|
||||
long time9=System.currentTimeMillis();
|
||||
log.info("耗时:"+(time9-time1)+"ms");
|
||||
return titleNumberVO;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "Annex 1";
|
||||
System.out.println(str.substring(0, str.length()-1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user