Search in sources :

Example 11 with CTRPrElt

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt in project poi by apache.

the class XSSFRichTextString method setStylesTableReference.

protected void setStylesTableReference(StylesTable tbl) {
    styles = tbl;
    if (st.sizeOfRArray() > 0) {
        //noinspection deprecation - for performance reasons!
        for (CTRElt r : st.getRArray()) {
            CTRPrElt pr = r.getRPr();
            if (pr != null && pr.sizeOfRFontArray() > 0) {
                String fontName = pr.getRFontArray(0).getVal();
                if (fontName.startsWith("#")) {
                    int idx = Integer.parseInt(fontName.substring(1));
                    XSSFFont font = styles.getFontAt(idx);
                    pr.removeRFont(0);
                    setRunAttributes(font.getCTFont(), pr);
                }
            }
        }
    }
}
Also used : CTRElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt) RichTextString(org.apache.poi.ss.usermodel.RichTextString)

Example 12 with CTRPrElt

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt in project poi by apache.

the class XSSFRichTextString method buildCTRst.

CTRst buildCTRst(String text, TreeMap<Integer, CTRPrElt> formats) {
    if (text.length() != formats.lastKey()) {
        throw new IllegalArgumentException("Text length was " + text.length() + " but the last format index was " + formats.lastKey());
    }
    CTRst stf = CTRst.Factory.newInstance();
    int runStartIdx = 0;
    for (Map.Entry<Integer, CTRPrElt> me : formats.entrySet()) {
        int runEndIdx = me.getKey();
        CTRElt run = stf.addNewR();
        String fragment = text.substring(runStartIdx, runEndIdx);
        run.setT(fragment);
        preserveSpaces(run.xgetT());
        CTRPrElt fmt = me.getValue();
        if (fmt != null) {
            run.setRPr(fmt);
        }
        runStartIdx = runEndIdx;
    }
    return stf;
}
Also used : CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) CTRElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt) RichTextString(org.apache.poi.ss.usermodel.RichTextString)

Aggregations

CTRPrElt (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt)10 CTRElt (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt)7 RichTextString (org.apache.poi.ss.usermodel.RichTextString)4 CTRst (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst)4 CTColor (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1 XmlObject (org.apache.xmlbeans.XmlObject)1 Test (org.junit.Test)1 CTComment (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment)1 CTFont (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont)1