Change font size in text box - apache poi word docx

∥☆過路亽.° 提交于 2019-12-13 03:44:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!