问题
I found the answer that explains how to insert a new text box into docx document.
create text box in document .docx using apache poi
The problem is that I cannot change the font size inside a newly created text box.
Does anyone know how to do that?
回答1:
Reference : create text box in document .docx using apache poi
The ctTxbxContent.addNewP()
in my code creates a CTP
object. The XWPFParagraph
has a constructor XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part)
. So you can get a XWPFParagraph
from the CTP
object and then use the default apache-poi
methods further.
...
CTTxbxContent ctTxbxContent = ctShape.addNewTextbox().addNewTxbxContent();
XWPFParagraph textboxparagraph = new XWPFParagraph(ctTxbxContent.addNewP(), (IBody)doc);
XWPFRun textboxrun = textboxparagraph.createRun();
textboxrun.setText("The TextBox text...");
textboxrun.setFontSize(24);
...
来源:https://stackoverflow.com/questions/35459386/change-font-size-in-text-box-apache-poi-word-docx