NPOI
NPOI copied to clipboard
[Word/*.docx] Can't set the correct font size
I want to modify a docx file. I try code:
public static XWPFParagraph AppendCellParagraph(XWPFTableCell cell, string text, Color fg = default, Color bg = default)
{
var p = cell.AddParagraph();
XWPFRun run = p.CreateRun();
run.SetText(text);
run.FontFamily = "宋体";
run.FontSize = 9; 👀
run.SetColor(ColorTranslator.ToHtml(fg));
p.AddRun(run);
p.FillBackgroundColor = ColorTranslator.ToHtml(bg == default ? Color.Transparent : bg);
p.Alignment = ParagraphAlignment.CENTER;
p.VerticalAlignment = TextAlignment.CENTER;
return p;
}
Test found that the actual font size is 10.5.