Search in sources :

Example 1 with CTTitle

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle in project poi by apache.

the class XSSFChart method getTitleFormula.

/**
	 * Get the chart title formula expression if there is one
	 * @return formula expression or null
	 */
public String getTitleFormula() {
    if (!chart.isSetTitle()) {
        return null;
    }
    CTTitle title = chart.getTitle();
    if (!title.isSetTx()) {
        return null;
    }
    CTTx tx = title.getTx();
    if (!tx.isSetStrRef()) {
        return null;
    }
    return tx.getStrRef().getF();
}
Also used : CTTx(org.openxmlformats.schemas.drawingml.x2006.chart.CTTx) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)

Example 2 with CTTitle

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle in project poi by apache.

the class XSSFChart method setTitleFormula.

/**
	 * Set the formula expression to use for the chart title
	 * @param formula
	 */
public void setTitleFormula(String formula) {
    CTTitle ctTitle;
    if (chart.isSetTitle()) {
        ctTitle = chart.getTitle();
    } else {
        ctTitle = chart.addNewTitle();
    }
    CTTx tx;
    if (ctTitle.isSetTx()) {
        tx = ctTitle.getTx();
    } else {
        tx = ctTitle.addNewTx();
    }
    if (tx.isSetRich()) {
        tx.unsetRich();
    }
    CTStrRef strRef;
    if (tx.isSetStrRef()) {
        strRef = tx.getStrRef();
    } else {
        strRef = tx.addNewStrRef();
    }
    strRef.setF(formula);
}
Also used : CTStrRef(org.openxmlformats.schemas.drawingml.x2006.chart.CTStrRef) CTTx(org.openxmlformats.schemas.drawingml.x2006.chart.CTTx) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)

Example 3 with CTTitle

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle in project poi by apache.

the class XSSFChart method setTitleText.

/**
     * Sets the title text as a static string.
     * @param newTitle to use
     */
public void setTitleText(String newTitle) {
    CTTitle ctTitle;
    if (chart.isSetTitle()) {
        ctTitle = chart.getTitle();
    } else {
        ctTitle = chart.addNewTitle();
    }
    CTTx tx;
    if (ctTitle.isSetTx()) {
        tx = ctTitle.getTx();
    } else {
        tx = ctTitle.addNewTx();
    }
    if (tx.isSetStrRef()) {
        tx.unsetStrRef();
    }
    CTTextBody rich;
    if (tx.isSetRich()) {
        rich = tx.getRich();
    } else {
        rich = tx.addNewRich();
        // body properties must exist (but can be empty)
        rich.addNewBodyPr();
    }
    CTTextParagraph para;
    if (rich.sizeOfPArray() > 0) {
        para = rich.getPArray(0);
    } else {
        para = rich.addNewP();
    }
    if (para.sizeOfRArray() > 0) {
        CTRegularTextRun run = para.getRArray(0);
        run.setT(newTitle);
    } else if (para.sizeOfFldArray() > 0) {
        CTTextField fld = para.getFldArray(0);
        fld.setT(newTitle);
    } else {
        CTRegularTextRun run = para.addNewR();
        run.setT(newTitle);
    }
}
Also used : CTTextParagraph(org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph) CTTextField(org.openxmlformats.schemas.drawingml.x2006.main.CTTextField) CTTx(org.openxmlformats.schemas.drawingml.x2006.chart.CTTx) CTTextBody(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle) CTRegularTextRun(org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)

Example 4 with CTTitle

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle in project poi by apache.

the class XSSFChart method getTitleText.

/**
     * Returns the title static text, or null if none is set.
     * Note that a title formula may be set instead.
     * Empty text result is for backward compatibility, and could mean the title text is empty or there is a formula instead.
     * Check for a formula first, falling back on text for cleaner logic.
     * @return static title text if set, 
     *         null if there is no title, 
     *         empty string if the title text is empty or the title uses a formula instead
	 */
public XSSFRichTextString getTitleText() {
    if (!chart.isSetTitle()) {
        return null;
    }
    // TODO Do properly
    CTTitle title = chart.getTitle();
    StringBuffer text = new StringBuffer();
    XmlObject[] t = title.selectPath("declare namespace a='" + XSSFDrawing.NAMESPACE_A + "' .//a:t");
    for (int m = 0; m < t.length; m++) {
        NodeList kids = t[m].getDomNode().getChildNodes();
        final int count = kids.getLength();
        for (int n = 0; n < count; n++) {
            Node kid = kids.item(n);
            if (kid instanceof Text) {
                text.append(kid.getNodeValue());
            }
        }
    }
    return new XSSFRichTextString(text.toString());
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XmlObject(org.apache.xmlbeans.XmlObject) Text(org.w3c.dom.Text) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)

Aggregations

CTTitle (org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)4 CTTx (org.openxmlformats.schemas.drawingml.x2006.chart.CTTx)3 XmlObject (org.apache.xmlbeans.XmlObject)1 CTStrRef (org.openxmlformats.schemas.drawingml.x2006.chart.CTStrRef)1 CTRegularTextRun (org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun)1 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)1 CTTextField (org.openxmlformats.schemas.drawingml.x2006.main.CTTextField)1 CTTextParagraph (org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 Text (org.w3c.dom.Text)1