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