Java Code Examples for org.apache.poi.xwpf.usermodel.XWPFRun#getText()

The following examples show how to use org.apache.poi.xwpf.usermodel.XWPFRun#getText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseWord07.java    From autopoi with Apache License 2.0 4 votes vote down vote up
/**
 * 解析这个段落
 * 
 * @Author JEECG
 * @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;
		}
	}

}
 
Example 2
Source File: ParseWord07.java    From jeasypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 解析这个段落
 * 
 * @Author JueYue
 * @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;
		}
	}

}
 
Example 3
Source File: ParseWord07.java    From easypoi with Apache License 2.0 4 votes vote down vote up
/**
 * 解析这个段落
 * 
 * @Author JueYue
 * @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;
        }
    }

}