如何为docx设置粗体运行Apache POI [英] How set bold for docx run apache poi

查看:161
本文介绍了如何为docx设置粗体运行Apache POI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置run.getCTR().getRPr()的粗体显示? 我写了这段代码,但是根本不起作用.

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);

现在,我想使用getCTR()将上述代码设置为粗体.我该怎么办? 谢谢.

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

推荐答案

如果需要run.getCTR().getRPr().setSzCs(size);来设置字体大小,则您正在使用Complex Script(Cs)字符.可能是特殊的双向(从右到左)语言(例如阿拉伯语)的字符.

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

这篇关于如何为docx设置粗体运行Apache POI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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