在文本框中更改字体大小-Apache POI Word DOCX [英] Change font size in text box - apache poi word docx

查看:411
本文介绍了在文本框中更改字体大小-Apache POI Word DOCX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I found the answer that explains how to insert a new text box into docx document.

在文档.docx中创建文本框使用apache poi

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆