diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java index 7ac0dce0..ec82fdf4 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/ReadTable.java @@ -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 wordAttributeMap = new HashMap<>(); public static Map nameToIdMap = new HashMap<>(); public static Map 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(); } @@ -154,7 +158,7 @@ public class ReadTable { */ public void writeAttrbute(String plid) { //boolean result = analysisWordTable(file); - //根据名称获取PAL制度模型 + //根据名称获取PAL制度模型 String sql = "update APP_ACT_COE_PAL_PROP set PROPERTYVALUE='%s' where PROPERTYID='%s' AND PLID='%s'"; nameToIdMap.forEach((key, value) -> { //根据key去更新 @@ -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,15 +256,34 @@ 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) { + //标题后续直接为table + if (nowPara.isInTable()) { + Table table = range.getTable(nowPara); + Map> tabelDocText = this.getHorizontalTableMapText(table); + tabelDocText.keySet().forEach(key -> { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fieldMap.put(key.replace(" ", ""), strings.get(0)); + fileFieldMap.put(key.replace(" ", ""), new WordField<>(strings.get(0))); + } + }); + i += table.numParagraphs(); + } continue; - }*/ + } //基本信息 - /*if (wordAttribute.getType().equals("DirectFeild")) { + if (wordAttribute.getType().equals("DirectFeild")) { int index = i + 1 > range.numParagraphs() ? i : i + 1; Paragraph paragraph = range.getParagraph(index); if ("无".equals(paragraph.text())) { @@ -271,19 +295,70 @@ public class ReadTable { if ("无".equals(paragraph.text())) { break; } - }*/ - //标题后续直接为table - if (nowPara.isInTable()) { - Table table = range.getTable(nowPara); - Map> tabelDocText = this.getHorizontalTableMapText(table); - tabelDocText.keySet().forEach(key -> { - List strings = tabelDocText.get(key); - if (!strings.isEmpty()) { - fieldMap.put(key.replace(" ", ""), strings.get(0)); - fileFieldMap.put(key.replace(" ", ""), new WordField<>(strings.get(0))); + } + //标题后续直接为table + if (paragraph.isInTable()) { + Table table = range.getTable(paragraph); + Map> tabelDocText = this.getHorizontalTableMapText(table); + + //在基本信息中特殊获取文件名称和版本号 + if (text.trim().equals("基本信息")) { + tabelDocText.keySet().forEach(key -> { + if (key.replaceAll(" ", "").equals("版本")) { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + version = strings.get(0); + } + } + if (key.equals("文件名称")) { + List strings = tabelDocText.get(key); + if (!strings.isEmpty()) { + fileName = strings.get(0); + } + } + }); } - }); - i += table.numParagraphs(); + + tabelDocText.keySet().forEach(key -> { + List 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> verticalTableText = this.getVerticalTableText(table); + + if (text.trim().equals("修订记录")) { + List 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 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> getVerticalTableText(Table table) { + Map> result = new HashMap<>(); + + List 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; + } + /** * 读取基本信息 * @@ -324,9 +432,9 @@ public class ReadTable { } sb.append(s); } - key = sb.toString().replaceAll(" ",""); + key = sb.toString().replaceAll(" ", ""); //看看是否是键值 - if(nameToIdMap.containsKey(key) && result.get(key) == null && j < (tr.numCells()-1)){ + if (nameToIdMap.containsKey(key) && result.get(key) == null && j < (tr.numCells() - 1)) { //取得单元格 j += 1; TableCell tdtmp = tr.getCell(j); @@ -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; diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java index bc4a1d8a..e1e99e96 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/TableConstant.java @@ -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\"}]"; } \ No newline at end of file diff --git a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/WordTableAttrFile.java b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/WordTableAttrFile.java index a963f5b3..a800e64d 100644 --- a/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/WordTableAttrFile.java +++ b/com.actionsoft.apps.coe.pal.datamigration/src/com/actionsoft/apps/coe/pal/datamigration/util/readtable/WordTableAttrFile.java @@ -69,7 +69,6 @@ public class WordTableAttrFile { for (int i =0;i