如何使用 run.getCTR().getRPr() 设置粗体运行? 我写了这段代码,但它根本不起作用。
run.setBold(true);
我在字体大小方面遇到了同样的问题,但我用以下代码修复了它:
CTHpsMeasure size = CTHpsMeasure.Factory.newInstance();
sizeFa.setVal(new BigInteger((sizePoint * 2) + ""));
run.getCTR().getRPr().setSz(size);
run.getCTR().getRPr().setSzCs(size);
现在我想使用上面的代码通过 getCTR() 设置粗体。我应该怎么办? 谢谢。
最佳答案
如果您需要使用run.getCTR().getRPr().setSzCs(size);
来设置字体大小,那么您正在使用复杂脚本
( Cs
) 字符。这可能是特殊双向(从右到左)语言(例如阿拉伯语)的字符。
因此,对于粗体,您应该尝试使用 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);
...
关于java - 如何为 docx run apache poi 设置粗体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46380259/