Java Code Examples for org.apache.poi.xssf.usermodel.XSSFRichTextString#numFormattingRuns()

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFRichTextString#numFormattingRuns() . 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: CellValueHelper.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 07版本复杂数据
 * 
 * @param rich
 * @return
 */
private String getXSSFRichString(XSSFRichTextString rich) {
	int nums = rich.numFormattingRuns();
	StringBuilder sb = new StringBuilder();
	String text = rich.toString();
	int currentIndex = 0, lastIndex = 0;
	for (int i = 1; i <= nums; i++) {
		sb.append("<span ");
		try {
			sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1)));
			sb.append("_");
			sb.append(cssRandom);
			sb.append("'");
		} catch (Exception e) {
		}
		sb.append(">");
		currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i);
		sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex)));
		sb.append("</span>");
		lastIndex = currentIndex;
	}
	return sb.toString();
}
 
Example 2
Source File: CellValueHelper.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 07版本复杂数据
 * 
 * @param rich
 * @return
 */
private String getXSSFRichString(XSSFRichTextString rich) {
	int nums = rich.numFormattingRuns();
	StringBuilder sb = new StringBuilder();
	String text = rich.toString();
	int currentIndex = 0, lastIndex = 0;
	for (int i = 1; i <= nums; i++) {
		sb.append("<span ");
		try {
			sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1)));
			sb.append("_");
			sb.append(cssRandom);
			sb.append("'");
		} catch (Exception e) {
		}
		sb.append(">");
		currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich.getIndexOfFormattingRun(i);
		sb.append(XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex)));
		sb.append("</span>");
		lastIndex = currentIndex;
	}
	return sb.toString();
}
 
Example 3
Source File: CellValueHelper.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 07版本复杂数据
 * @param rich
 * @return
 */
private String getXSSFRichString(XSSFRichTextString rich) {
    int nums = rich.numFormattingRuns();
    StringBuilder sb = new StringBuilder();
    String text = rich.toString();
    int currentIndex = 0, lastIndex = 0;
    for (int i = 1; i <= nums; i++) {
        sb.append("<span ");
        try {
            sb.append("class='font_" + getFontIndex(rich.getFontOfFormattingRun(i - 1)));
            sb.append("_");
            sb.append(cssRandom);
            sb.append("'");
        } catch (Exception e) {
        }
        sb.append(">");
        currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich
            .getIndexOfFormattingRun(i);
        sb.append(XmlEscapers.xmlContentEscaper().escape(
            text.substring(lastIndex, currentIndex)));
        sb.append("</span>");
        lastIndex = currentIndex;
    }
    return sb.toString();
}