We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Why is my style not being applied to my range?

I am creating a range, giving it a value, and styling it up like so:

private string fontForSheets = "Calibri";

Range unitNameRange = locationWorksheet.Cells.CreateRange(“A1”, “D1”);

unitNameRange.PutValue(_unit, false, true); // val, isConverted, SetStyle. Don’t know if these bools are right…
CellsFactory cf = new CellsFactory();
Style style = cf.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Left;
style.Font.Name = fontForSheets;
style.Font.IsBold = true;
style.Font.Size = 14;
unitNameRange.SetStyle(style);

<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>But the style is not “taking” - the value is a simple, generic, bit of text; it is Arial 10, no bolding. How can I get the style to adhere to the range?<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; background-color: rgb(255, 255, 255);”>Is either the second or third, or both, wrong? I was guessing when setting isConverted to false and SetStyle to true…

Hi Clay,


Thank you for contacting Aspose support.

I have evaluated the presented scenario while using the latest version of Aspose.Cells for .NET 16.12.6 and following piece of code. I am afraid, I am not able to observe any problem with the resultant spreadsheet (attached) as the style has been correctly applied. Please test the case against the latest version. In case the problem persists, please share an executable sample application along with input spreadsheet and your current result.

C#

string fontForSheets = “Calibri”;
var book = new Workbook();
var locationWorksheet = book.Worksheets[0];
Range unitNameRange = locationWorksheet.Cells.CreateRange(“A1”, “D1”);
unitNameRange.PutValue(“100”, false, true); // val, isConverted, SetStyle. Don’t know if these bools are right…
CellsFactory cf = new CellsFactory();
Style style = cf.CreateStyle();
style.HorizontalAlignment = TextAlignmentType.Left;
style.Font.Name = fontForSheets;
style.Font.IsBold = true;
style.Font.Size = 14;
unitNameRange.SetStyle(style);
book.Save(dataDir + “output.xlsx”);