You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/12/08 12:26:50 UTC
[Bug 60454] the XWPFRun object can not recognize its superscript
https://bz.apache.org/bugzilla/show_bug.cgi?id=60454
Mark Murphy <jm...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #1 from Mark Murphy <jm...@apache.org> ---
This works for me:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class TestVerticalAlign {
public static void main(String[] args) {
XWPFDocument doc = new XWPFDocument();
XWPFParagraph p = doc.createParagraph();
XWPFRun r = p.createRun();
r.setText("This is some Text");
r = p.createRun();
r.setSubscript(VerticalAlign.SUBSCRIPT);
r.setText(" This is subscript text");
r = p.createRun();
r.setSubscript(VerticalAlign.SUPERSCRIPT);
r.setText(" This is superscript text");
XWPFParagraph p2 = doc.createParagraph();
r = p2.createRun();
for (XWPFRun r2 : p.getRuns()) {
switch (r2.getSubscript()) {
case BASELINE:
r.addCarriageReturn();
r.setText("Normal Text");
break;
case SUBSCRIPT:
r.addCarriageReturn();
r.setText("Subscript Text");
break;
case SUPERSCRIPT:
r.addCarriageReturn();
r.setText("Superscript Text");
break;
default:
r.addCarriageReturn();
r.setText("Unknown Text Alignment");
break;
}
}
// Write the Document in file system
try {
FileOutputStream out = new FileOutputStream(new File(
"valigntest.docx"));
doc.write(out);
out.close();
doc.close();
System.out.println("valigntest.docx written
successully");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org