How set bold for docx run apache poi

谁说我不能喝 提交于 2019-12-12 04:09:28

问题


How set bold for run with run.getCTR().getRPr()? I write this code but it doesn't work at all.

run.setBold(true);

I had the same problem with font-size but I fixed it with this code:

CTHpsMeasure size = CTHpsMeasure.Factory.newInstance();
sizeFa.setVal(new BigInteger((sizePoint * 2) + ""));
run.getCTR().getRPr().setSz(size);
run.getCTR().getRPr().setSzCs(size);

Now I want to set bold with code like above, with getCTR(). what should I do? Thanks.


回答1:


If run.getCTR().getRPr().setSzCs(size); is needed for you to set the font size, then you are using Complex Script (Cs) characters. That might be characters of special bidirectional (right to left) language (arabic for example).

So for bold you should try using CTRPr.setBCs.

import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
...
  run.setBold(true);
  CTOnOff ctonoff = CTOnOff.Factory.newInstance();
  ctonoff.setVal(STOnOff.ON);
  run.getCTR().getRPr().setBCs(ctonoff);
...


来源:https://stackoverflow.com/questions/46380259/how-set-bold-for-docx-run-apache-poi

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