Style - Setting 'Arial' or another other font is being overrided by Calibri

Hello,

We are using the latest aspose DLL. For some reason when trying to set the font in this fashion, it’s being output as Calibri instead.

Here’s the code sample:

StyleFlag stlFlg = new StyleFlag();
stlFlg.All = true;

Style stl = wsheet.Workbook.Styles[wsheet.Workbook.Styles.Add()];
stl.Font.IsBold = true;
stl.Font.Name = "Arial";
stl.Font.Size = 10;
stl.IsTextWrapped = true;
stl.ForegroundColor = System.Drawing.Color.LightGray;
stl.Pattern = BackgroundType.Solid;
stl.VerticalAlignment = TextAlignmentType.Bottom;
stl.HorizontalAlignment = TextAlignmentType.Center;

stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;

Range target = wsheet.Cells.CreateRange(9, 4, rowCount, colCount - 4);
target.ApplyStyle(stl, stlFlg);

Thanks

Hi,

I was investigating it and found the problem does not exist in latest version Aspose.Cells
for .NET 5.3.0.5


Also see the output of the code and the screenshot.

C#

//Instantiate a new Workbook.

Workbook workbook = new Workbook();


//Get the first worksheet in the book.

Worksheet wsheet = workbook.Worksheets[0];


//Create a style flag

StyleFlag stlFlg = new StyleFlag();

stlFlg.All = true;


//The problem was in this line

Style stl;// = wsheet.Workbook.Styles[wsheet.Workbook.Styles.Add()];


//I have added this line now

stl = workbook.Styles[workbook.Styles.Add()];


//Set other attributes of style

stl.Font.IsBold = true;

stl.Font.Name = “Arial”;

stl.Font.Size = 10;

stl.IsTextWrapped = true;

stl.ForegroundColor = System.Drawing.Color.LightGray;

stl.Pattern = BackgroundType.Solid;

stl.VerticalAlignment = TextAlignmentType.Bottom;

stl.HorizontalAlignment = TextAlignmentType.Center;

stl.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;

stl.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;


//Create a range and apply the style

Range target = wsheet.Cells.CreateRange(1, 1, 10, 10);

target.ApplyStyle(stl, stlFlg);


//Save the excel file.

workbook.Save(“f:\downloads\output.xlsx”);

Screenshot

thanks, but I think the issue is this.

The issue is when we add style.Font.IsBold = true. Without this statement, the font remains as Arial, but if we set the font to bold, then it changes to Calibri.

Hi,

I could not replicate the problem mentioned by you. Please see the output files with and without setting fontbold property.