如何在C#Windows窗体中使用具有空格的字体来创建excel workseet?

问题描述 投票:0回答:1

我正在使用IEnumerable变量在C#Windows窗体应用程序中创建Excel工作表。问题是,如果字体名称有1个单词(例如),我可以设置创建的工作表字体。 'IRNazanin',但对于带空格的字体名称,则不起作用。 “ B Mitra”。我的代码是:

var wb = new XLWorkbook { RightToLeft = true };
var ws = wb.Worksheets.Add("Sick_Information");
ws.Columns().AdjustToContents();
ws.Style.Font.FontName = "B Mitra";

我尝试使用字体名称:

  • 不加延误,例如“ BMitra”
  • 带连字符,例如“ B-Mitra”
  • 带下划线,例如“ B_Mitra”
  • 带有额外的单个qout,例如“'B Mitra'”

仍然无法正常工作。我在ClosedXML.Excel版本ClosedXML和MS Office 2016中使用0.94.2.0库。Excel将获得字体名称,但不会应用它。

enter image description here

True B Mitra字体是这样的。 (手动更改)

enter image description here

客户需要带有B Mitra字体和波斯数字的文件。因此,我别无选择来更改字体。

c# excel winforms closedxml
1个回答
0
投票

如果使用的是ClosedXML库,请尝试使用setFontName方法:

ws.Style.Font.SetFontName("B Mitra");
© www.soinside.com 2019 - 2024. All rights reserved.