I am experiencing issues with RichText and Workbook.DefaultFontName in the latest Spire.Office 6.12.1 targeting .NET 5.0. I was able to create a minimum example code:
- Code: Select all
using (var workbook = new Workbook())
{
workbook.DefaultFontName = "Calibri Light";
workbook.DefaultFontSize = 14;
workbook.Worksheets.Clear();
var worksheet = workbook.Worksheets.Add("test");
worksheet.Range[1, 1].Text = "Some normal text";
var boldFont = workbook.CreateFont();
boldFont.IsBold = true;
worksheet.Range[2, 1].RichText.Text += "regular bold regular";
worksheet.Range[2, 1].RichText.SetFont(8, 11, boldFont);
worksheet.Range.Style.VerticalAlignment = VerticalAlignType.Center;
workbook.SaveToFile("text.xlsx", ExcelVersion.Version2016);
}
when I open the created file I get the following situation, where the first cell has font Arial with size 10, as well as the first part of the richtext:
Interestingly, if I change the richtext to "regular bold" (removing the last "regular"), the problem goes away:
It seems that the problem only occurs when the endPost argument of the RichText.SetFont(int startPos, int endPost, ExcelFont font) method is not equal to the full length of the richtext.
Do you have any workaround?
I also tried adding
- Code: Select all
var regularFont = workbook.CreateFont();
worksheet.Range[2, 1].RichText.SetFont(13, 19, regularFont);
but it does not solve the problem.
Thanks,
Francesco