dotnetcore / NPOI

A .NET library for reading and writing Microsoft Office binary and OOXML file formats.
Apache License 2.0
1.93k stars 413 forks source link

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

Open CodingOctocat opened 4 years ago

CodingOctocat commented 4 years ago

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.