コード例 #1
0
ファイル: ParseWord07.java プロジェクト: goozi/winter
 /**
  * 解析这个段落
  *
  * @author Zerrion
  * @date 2013-11-16
  * @param paragraph
  * @param map
  */
 private void parseThisParagraph(XWPFParagraph paragraph, Map<String, Object> map)
     throws Exception {
   XWPFRun run;
   XWPFRun currentRun = null; // 拿到的第一个run,用来set值,可以保存格式
   String currentText = ""; // 存放当前的text
   String text;
   Boolean isfinde = false; // 判断是不是已经遇到{{
   List<Integer> runIndex = new ArrayList<Integer>(); // 存储遇到的run,把他们置空
   for (int i = 0; i < paragraph.getRuns().size(); i++) {
     run = paragraph.getRuns().get(i);
     text = run.getText(0);
     if (StringUtils.isEmpty(text)) {
       continue;
     } // 如果为空或者""这种这继续循环跳过
     if (isfinde) {
       currentText += text;
       if (currentText.indexOf("{{") == -1) {
         isfinde = false;
         runIndex.clear();
       } else {
         runIndex.add(i);
       }
       if (currentText.indexOf("}}") != -1) {
         changeValues(paragraph, currentRun, currentText, runIndex, map);
         currentText = "";
         isfinde = false;
       }
     } else if (text.indexOf("{") >= 0) { // 判断是不是开始
       currentText = text;
       isfinde = true;
       currentRun = run;
     } else {
       currentText = "";
     }
     if (currentText.indexOf("}}") != -1) {
       changeValues(paragraph, currentRun, currentText, runIndex, map);
       isfinde = false;
     }
   }
 }