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();
}
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);
}
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);
}
}
Aggregations