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

Free Support Forum - aspose.com

Cell.Style property vs Cell.GetStyle/SetStyle method

Since v4.4.2, we add two new methods to format a cell: Cell.GetStyle method and Cell.SetStyle method.

So now you can use following two ways to format a cell:

1. use Cell.Style property


cell.Style.Font.IsBold = true;


cell.Style.Font.IsBold = True

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 2. use Cell.GetStyle and Cell.SetStyle method


Style style = cell.GetStyle();

style.Font.IsBold = true;



Dim style as Style = cell.GetStyle()

style.Font.IsBold = True


You can see that the first approach is easy and straight-forward. So why we add the second approach?

When you use the first piece of code, a Style object will be initiated for each cell when formatting it. So if there are a lot of cells to be formatted, a large amount of memory will be consumed becasue Style object is a large object. These Style objects won't be freed until calling Workbook.Save method.

So we add the second approach to optimize memory usage. After you use Cell.GetStyle method to retrieve a Style object, modify it and use Cell.SetStyle method to set back to this cell, this Style object won't be preserved and .NET GC will collect it when it's not referenced.

Actually when calling Cell.SetStyle method, Style object won't be saved for each cell. Instead, we compare this Style object to an interal Style object pool to see if it can be reused. Only different Style objects will be kept for each Workbook object. So there are only several hundred Style objects for each Excel file. For each cell, only an index to this Style object pool will be preserved.

We have tested it and find it will save a large amount of memory when processing very large Excel files.