问题描述
我找到了答案,该答案解释了如何在docx文档中插入新的文本框.
I found the answer that explains how to insert a new text box into docx document.
问题是我无法在新创建的文本框中更改字体大小.
The problem is that I cannot change the font size inside a newly created text box.
有人知道怎么做吗?
推荐答案
参考:
我的代码中的ctTxbxContent.addNewP()
创建一个CTP
对象. XWPFParagraph
具有构造函数XWPFParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP prgrph, IBody part)
.因此,您可以从CTP
对象获得XWPFParagraph
,然后进一步使用默认的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);
...
这篇关于在文本框中更改字体大小-Apache POI Word DOCX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!