use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextField in project poi by apache.
the class XSLFTextRun method getRenderableText.
String getRenderableText() {
if (_r instanceof CTTextField) {
CTTextField tf = (CTTextField) _r;
XSLFSheet sheet = _p.getParentShape().getSheet();
if ("slidenum".equals(tf.getType()) && sheet instanceof XSLFSlide) {
return Integer.toString(((XSLFSlide) sheet).getSlideNumber());
}
return tf.getT();
} else if (_r instanceof CTTextLineBreak) {
return "\n";
}
String txt = ((CTRegularTextRun) _r).getT();
TextCap cap = getTextCap();
StringBuffer buf = new StringBuffer();
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
if (c == '\t') {
// TODO: finish support for tabs
buf.append(" ");
} else {
switch(cap) {
case ALL:
buf.append(Character.toUpperCase(c));
break;
case SMALL:
buf.append(Character.toLowerCase(c));
break;
default:
buf.append(c);
}
}
}
return buf.toString();
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTTextField 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