NPOI icon indicating copy to clipboard operation
NPOI copied to clipboard

[Word/*.docx] Can't set the correct font size

Open CodingOctocat opened this issue 4 years ago • 0 comments

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.

CodingOctocat avatar Mar 18 '20 12:03 CodingOctocat