需求描述:当结论不合格时,文字的背景色需要为灰色,效果如下图
核心代码,paragraph为XWPFParagraph段落。
if(entity.Conclusion=="不合格")
{
XWPFRun run = paragraph.Runs[0];
CT_RPr ctrpr = run.GetCTR().rPr;
if(ctrpr == null)
{
ctrpr = run.GetCTR().AddNewRPr();
}
CT_Shd ctshd = ctrpr.shd;
if (ctshd == null)
{
ctshd = ctrpr.AddNewShd();
}
ctshd.val = ST_Shd.pct50;
ctshd.color = "#B7B7B7";
}
标签:run,ctrpr,ctshd,NPOI,背景色,word,null,GetCTR
From: https://www.cnblogs.com/oBehavior/p/17874457.html