| @@ -24,6 +24,7 @@ import cn.afterturn.easypoi.word.parse.excel.ExcelEntityParse; | |||
| import cn.afterturn.easypoi.word.parse.excel.ExcelMapParse; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.poi.xwpf.usermodel.*; | |||
| import org.apache.xmlbeans.XmlCursor; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -255,6 +256,10 @@ public class ParseWord07 { | |||
| } | |||
| private void parseWordSetValue(MyXWPFDocument doc, Map<String, Object> map) throws Exception { | |||
| //时间紧迫,先写死(金茂合同) | |||
| if(map.get("operationType") != null && "3".equals(map.get("operationType").toString())){ | |||
| parseJinmaoParagraphic(doc, map); | |||
| } | |||
| // 第一步解析文档 | |||
| parseAllParagraphic(doc.getParagraphs(), map); | |||
| // 第二步解析页眉,页脚 | |||
| @@ -294,4 +299,64 @@ public class ParseWord07 { | |||
| } | |||
| /** | |||
| * 处理金茂合同(时间紧迫,先写死) | |||
| * | |||
| * @param doc | |||
| * @param map | |||
| * @throws Exception | |||
| */ | |||
| private void parseJinmaoParagraphic(MyXWPFDocument doc, Map<String, Object> map) throws Exception { | |||
| String typeStr = map.get("type") == null ?"":map.get("type").toString(); | |||
| String countRatioListStr = map.get("countRatioList") == null ?"":map.get("countRatioList").toString(); | |||
| if(StringUtils.isBlank(typeStr) || StringUtils.isBlank(countRatioListStr)){ | |||
| return ; | |||
| } | |||
| int type = 0,countRatioList = 0; | |||
| try { | |||
| type = Integer.parseInt(typeStr); | |||
| countRatioList = Integer.parseInt(countRatioListStr); | |||
| } catch (NumberFormatException e) { | |||
| return ; | |||
| } | |||
| if(type < 1 || type > 3 || countRatioList < 2){ | |||
| return ; | |||
| } | |||
| int index = 0; | |||
| List<XWPFParagraph> paragraphs = doc.getParagraphs(); | |||
| XWPFParagraph paragraph; | |||
| for (int i = 0; i < paragraphs.size(); i++) { | |||
| paragraph = paragraphs.get(i); | |||
| if (paragraph.getText().indexOf("b.租金递增:") != -1) { | |||
| index++; | |||
| if(index == type){ | |||
| List<XWPFRun> runs = paragraph.getRuns(); | |||
| XmlCursor xmlCursor = paragraph.getCTP().newCursor(); | |||
| for (int k = 1;k < countRatioList;k++){ | |||
| int n = k+2; | |||
| xmlCursor.toNextSibling(); | |||
| XWPFParagraph newParagraph = doc.insertNewParagraph(xmlCursor); | |||
| i++; | |||
| newParagraph.getCTP().setPPr(paragraph.getCTP().getPPr()); | |||
| for (int j = 1;j < runs.size(); j++){ | |||
| XWPFRun run = runs.get(j); | |||
| String text = run.getText(0); | |||
| if(text.endsWith("2")){ | |||
| text = text.replace("2",n+""); | |||
| } | |||
| System.out.println("--"+text); | |||
| XWPFRun newRun = newParagraph.createRun(); | |||
| newRun.setText(text); | |||
| newRun.getCTR().setRPr(run.getCTR().getRPr()); | |||
| } | |||
| xmlCursor = newParagraph.getCTP().newCursor(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||