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

查看:45
本文介绍了如何为 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).

所以对于大胆你应该尝试使用 CTRPr.setBCs.

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天全站免登陆