如何为 docx 运行 apache poi 设置粗体
How set bold for docx run apache poi
如何使用 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);
来设置字体大小,那么您正在使用 Complex Script
(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);
...
如何使用 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);
来设置字体大小,那么您正在使用 Complex Script
(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);
...