Search in sources :

Example 1 with CTTx

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTx 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 CTTx

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTx 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 CTTx

use of org.openxmlformats.schemas.drawingml.x2006.chart.CTTx 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)

Aggregations

CTTitle (org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)3 CTTx (org.openxmlformats.schemas.drawingml.x2006.chart.CTTx)3 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