在文本框中更改字体大小 - apache poi word docx

时间:2016-02-17 14:26:46

标签: apache textbox ms-word apache-poi docx

我找到了解释如何在docx文档中插入新文本框的答案。

create text box in document .docx using apache poi

问题是我无法更改新创建的文本框中的字体大小。

有谁知道怎么做?

1 个答案:

答案 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);
...