表单解析~添加新的模板
This commit is contained in:
parent
da83bb87f0
commit
f67af816b3
@ -33,6 +33,10 @@ import java.util.*;
|
||||
* @date 2022/6/30 21:47
|
||||
*/
|
||||
public class ReadTable {
|
||||
//相关文件、存文件名称
|
||||
private String version = "";
|
||||
|
||||
private String fileName = "";
|
||||
public static Map<String, WordAttribute> wordAttributeMap = new HashMap<>();
|
||||
public static Map<String, String> nameToIdMap = new HashMap<>();
|
||||
public static Map<String, String> idToNameMap = new HashMap<>();
|
||||
@ -140,7 +144,7 @@ public class ReadTable {
|
||||
DCContext dcContextpdf1 = new DCContext(userContext, dcProfilepdfdoc, "com.actionsoft.apps.coe.pal.datamigration", groupValue, fileValue, docxname);
|
||||
InputStream docxfile = SDK.getDCAPI().read(dcContextpdf1);
|
||||
try {
|
||||
new WordTableAttrFile().copyWord(userContext, shapId, docxfile, id, "评估表|评价表|表单$", "s");
|
||||
new WordTableAttrFile().copyWord(userContext, shapId, docxfile, id, "评估表|评价表|表单|检查表$", "s");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -232,6 +236,7 @@ public class ReadTable {
|
||||
HWPFDocument doc = new HWPFDocument(file);
|
||||
//XWPFDocument doc = new XWPFDocument(file);
|
||||
Range range = doc.getRange();
|
||||
int titleover = 0;
|
||||
for (int i = 0; i < range.numParagraphs(); i++) {
|
||||
Paragraph nowPara = range.getParagraph(i);
|
||||
String text = nowPara.text();
|
||||
@ -243,7 +248,7 @@ public class ReadTable {
|
||||
}
|
||||
if (ischeck) {
|
||||
boolean isTitle = isTitle(nowPara);
|
||||
if (isTitle) {
|
||||
if (isTitle && titleover < 2) {
|
||||
String title = "";
|
||||
if (fieldMap.get("标题") != null) {
|
||||
title = fieldMap.get("标题").toString();
|
||||
@ -251,27 +256,17 @@ public class ReadTable {
|
||||
title = title + nowPara.text().replace("\r", "");
|
||||
fieldMap.put("标题", title);
|
||||
fileFieldMap.put("标题", new WordField<>(title));
|
||||
titleover = 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (titleover == 1) {
|
||||
titleover = 2;
|
||||
ischeck = false;
|
||||
}
|
||||
|
||||
/*WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||
WordAttribute wordAttribute = wordAttributeMap.get(text.trim());
|
||||
if (null == wordAttribute) {
|
||||
continue;
|
||||
}*/
|
||||
//基本信息
|
||||
/*if (wordAttribute.getType().equals("DirectFeild")) {
|
||||
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
||||
Paragraph paragraph = range.getParagraph(index);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
continue;
|
||||
}
|
||||
while (!paragraph.isInTable()) {
|
||||
i += 1;
|
||||
paragraph = range.getParagraph(i);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
//标题后续直接为table
|
||||
if (nowPara.isInTable()) {
|
||||
Table table = range.getTable(nowPara);
|
||||
@ -285,6 +280,86 @@ public class ReadTable {
|
||||
});
|
||||
i += table.numParagraphs();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//基本信息
|
||||
if (wordAttribute.getType().equals("DirectFeild")) {
|
||||
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
||||
Paragraph paragraph = range.getParagraph(index);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
continue;
|
||||
}
|
||||
while (!paragraph.isInTable()) {
|
||||
i += 1;
|
||||
paragraph = range.getParagraph(i);
|
||||
if ("无".equals(paragraph.text())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//标题后续直接为table
|
||||
if (paragraph.isInTable()) {
|
||||
Table table = range.getTable(paragraph);
|
||||
Map<String, List<String>> tabelDocText = this.getHorizontalTableMapText(table);
|
||||
|
||||
//在基本信息中特殊获取文件名称和版本号
|
||||
if (text.trim().equals("基本信息")) {
|
||||
tabelDocText.keySet().forEach(key -> {
|
||||
if (key.replaceAll(" ", "").equals("版本")) {
|
||||
List<String> strings = tabelDocText.get(key);
|
||||
if (!strings.isEmpty()) {
|
||||
version = strings.get(0);
|
||||
}
|
||||
}
|
||||
if (key.equals("文件名称")) {
|
||||
List<String> strings = tabelDocText.get(key);
|
||||
if (!strings.isEmpty()) {
|
||||
fileName = strings.get(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
tabelDocText.keySet().forEach(key -> {
|
||||
List<String> strings = tabelDocText.get(key);
|
||||
if (!strings.isEmpty()) {
|
||||
fieldMap.put(key, strings.get(0));
|
||||
fileFieldMap.put(key, new WordField<>(strings.get(0)));
|
||||
}
|
||||
});
|
||||
i += table.numParagraphs();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
//修订信息
|
||||
if (wordAttribute.getType().equals("VerticalFeild")) {
|
||||
int index = i + 1 > range.numParagraphs() ? i : i + 1;
|
||||
Paragraph paragraph = range.getParagraph(index);
|
||||
int level = paragraph.getIlvl();
|
||||
if (paragraph.isInTable()) {
|
||||
Table table = range.getTable(paragraph);
|
||||
Map<String, List<String>> verticalTableText = this.getVerticalTableText(table);
|
||||
|
||||
if (text.trim().equals("修订记录")) {
|
||||
List<String> strings = verticalTableText.get("版本");
|
||||
int subIndex = 0;
|
||||
for (int j = 0; j < strings.size(); j++) {
|
||||
String s = strings.get(j);
|
||||
if (s.equals(version)) {
|
||||
subIndex = j;
|
||||
}
|
||||
}
|
||||
for (String key : verticalTableText.keySet()) {
|
||||
List<String> values = verticalTableText.get(key);
|
||||
fieldMap.put(key, values.get(subIndex));
|
||||
fileFieldMap.put(key, new WordField<>(values.get(subIndex)));
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
i += table.numParagraphs();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// continue;
|
||||
//}
|
||||
}
|
||||
@ -295,6 +370,39 @@ public class ReadTable {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取竖排的表格
|
||||
*
|
||||
* @param table
|
||||
* @return
|
||||
*/
|
||||
private Map<String, List<String>> getVerticalTableText(Table table) {
|
||||
Map<String, List<String>> result = new HashMap<>();
|
||||
|
||||
List<String> stringList = new ArrayList<>();
|
||||
for (int i = 0; i < table.numRows(); i++) {
|
||||
TableRow row = table.getRow(i);
|
||||
for (int j = 0; j < row.numCells(); j++) {
|
||||
TableCell cell = row.getCell(j);
|
||||
String text = cell.text();
|
||||
//去除text特殊符号
|
||||
if (null != text && !"".equals(text)) {
|
||||
text = text.replaceAll("\\p{C}", "");
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
//首行为标题行
|
||||
result.put(text, new ArrayList<>());
|
||||
stringList.add(text);
|
||||
} else {
|
||||
result.get(stringList.get(j)).add(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取基本信息
|
||||
*
|
||||
@ -451,7 +559,7 @@ public class ReadTable {
|
||||
fontName = characterRun.getFontName();
|
||||
if (fontName.contains("黑体")) {
|
||||
//与文档fontsize标号2倍关系 ,黑体一号 等于 26号size
|
||||
return characterRun.getFontSize() == 44;
|
||||
return (characterRun.isBold() && characterRun.getFontSize() == 52) || characterRun.getFontSize() == 44;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.actionsoft.apps.coe.pal.datamigration.util.readtable;
|
||||
|
||||
public class TableConstant {
|
||||
public final static String WORDIMPORT = "[{\"title\":\"基本信息\",\"type\":\"DirectFeild\"}]";
|
||||
public final static String WORDIMPORT = "[{\"title\":\"基本信息\",\"type\":\"DirectFeild\"},{\"title\":\"修订记录\",\"type\":\"VerticalFeild\"}]";
|
||||
//public final static String NAMETOID = "[{\"title\":\"目的\",\"type\":\"goal\"},{\"title\":\"拟制/修订人\",\"type\":\"reviser\"},{\"title\":\"拟制/修订日期\",\"type\":\"reviseddate\"},{\"title\":\"审核人\",\"type\":\"auditor\"},{\"title\":\"复核人\",\"type\":\"reviewer\"},{\"title\":\"审批人\",\"type\":\"approver\"},{\"title\":\"术语\",\"type\":\"term\"},{\"title\":\"术语定义\",\"type\":\"definition\"},{\"title\":\"组织/角色名称\",\"type\":\"Character\"},{\"title\":\"组织/角色职责\",\"type\":\"responsibilities\"},{\"title\":\"相关文件\",\"type\":\"relevant\"},{\"title\":\"支持文件\",\"type\":\"support\"},{\"title\":\"相关知识\",\"type\":\"related\"},{\"title\":\"附则\",\"type\":\"supplementary\"}]";
|
||||
public final static String NAMETOID = "[" +
|
||||
"{\"title\":\"文件名称\",\"type\":\"Form_name\"}," +
|
||||
@ -11,5 +11,12 @@ public class TableConstant {
|
||||
"{\"title\":\"适用范围\",\"type\":\"form_Scope_application\"}," +
|
||||
"{\"title\":\"L1\",\"type\":\"Process_Architecture_L1\"}," +
|
||||
"{\"title\":\"L2\",\"type\":\"Process_Architecture_L2\"}," +
|
||||
"{\"title\":\"L3\",\"type\":\"Process_Architecture_L3\"}]";
|
||||
"{\"title\":\"L3\",\"type\":\"Process_Architecture_L3\"}," +
|
||||
"{\"title\":\"拟制/修订日期\",\"type\":\"Drafted_and_revised_date\"}," +
|
||||
"{\"title\":\"拟制/修订人\",\"type\":\"Drafted_and_revised_by\"}," +
|
||||
"{\"title\":\"审核人\",\"type\":\"auditor\"}," +
|
||||
"{\"title\":\"复核人\",\"type\":\"reviewer\"}," +
|
||||
"{\"title\":\"审批人\",\"type\":\"approver\"}," +
|
||||
"{\"title\":\"审批人\",\"type\":\"approver\"}," +
|
||||
"{\"title\":\"拟制/修订单位\",\"type\":\"Issuing_department\"}]";
|
||||
}
|
||||
@ -69,7 +69,6 @@ public class WordTableAttrFile {
|
||||
for (int i =0;i<elementsList.size();i++) {
|
||||
IBodyElement bodyElement = elementsList.get(i);
|
||||
BodyElementType elementType = bodyElement.getElementType();
|
||||
System.out.println(elementType);
|
||||
if (elementType == BodyElementType.PARAGRAPH) {
|
||||
XWPFParagraph srcPr = (XWPFParagraph) bodyElement;
|
||||
String tmptext = srcPr.getParagraphText();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user