我找到了解释如何在docx文档中插入新文本框的答案。
create text box in document .docx using apache poi
问题是我无法更改新创建的文本框中的字体大小。
有谁知道怎么做?
答案 0 :(得分:0)
参考:create text box in document .docx using apache poi
我的代码中的ctTxbxContent.addNewP()
会创建一个CTP
对象。 XWPFParagraph
有一个构造函数XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part)
。因此,您可以从XWPFParagraph
对象获取CTP
,然后再使用默认的apache-poi
方法。
...
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);
...