Styles question


Is possible to change several style attributes to a range cells without alter the other font or color properties?, I test it setting a new style to the range but the new style overload any other setting to this cells.

For example, I have a range with different fonts and size and I want to change the background color of that cells without change the font property, is this possible?

Thank You.
Alejandro Diaz


Dear Alejandro,

Sorry, our current release doesn’t provide that option.

Instead, you can assign the background color of the range using Range.Style, then assign the style to each cell. Of course, please pay attention to the background color you are assigning to each cell.


Is there a problem to create a new style for each cell in the range? Is there a limit for quantity of styles?, does aspose.excel eliminate the duplicate styles?

The problem I have is when I modified a style for one cell, this modification also alter all other cells (out of the range) of this style.

Thank You


Dear Alejandro,

If you want to create a new style for each cell in the range, you can use Cell.Style or Cell.Format to set cell style seperatedly.

Yes, the quantity of styles is limited by Microsoft Excel.

Currently Aspose.Excel does not eliminate the duplicate styles. Your questions are very helpful, I plan to eliminate the duplicate styles in the future release.

If you want to modify a single cell’s style without altering other cells of this style, please create a new style object to set the style of the cell.


do you know how many styles support Microsoft Excel?

If I try to don’t insert duplicate style I have problems verifing two styles are equal because the style class has many properties and this properties don’t have comparation operator.

Do you can add operator = in style class?

Thank You


Dear negware,

About 512 different styles are supported in Microsoft Excel according to my own test. Surplus styles is discarded by Microsoft Excel.

Thanks for your suggestion.

I am thinking about to merge the same styles. If too many styles is set, an exception will be thrown.


following your instruction when I need to change any style property to a cell I create a new style with every property of the old style.
That works fine for every property except the borders. If the cell was designed using Microsoft excel and drawed with a border around a range of cells, any cell at the perimeter of the range has a different style of border.

How can I reproduce that style in order to create a new one based on this one?

Thank You


Dear Alejandro,

Because combining styles set by different ways is sophisticate, currently Aspose.Excel has some priorities to create style.

From low to high:
1. Styles set in designer file
2. Styles set by Cell.Style
3. Styles set by Cell.Format

High priority style will override low priority style. So if you change a cell’s style and want to reserve the designer file’s style, you have to re-set style in your code.

That’s not very convenient. I will improve style setting method in future release, maybe in next month.


Hi Laurence,
in the case I want to change a style property (color or font) to a cell with the style set in designer file, how can I create a new style based in the style the cell has set?

I mean, I can create a new style and assign every property from the old to the new style, except borders because there is only one method to assign it (Borders.SetStyle - Sets the style of all borders of the collection).

If the cell at designed file has different line style at BottomBorder, TopBorder, LeftBorder or/and RightBorder; I don’t find a way to reproduce that borders style with the method availale in the aspose API because the SetStyle methon sets the same line style to ALL borders of the collection. Do you understand my problem?

Thank you in advance.


Dear Alejandro,

Please see the following sample code:

int styleIndex = excel.Styles.Add();
Style style = excel.Styles.GetAt(styleIndex);

//Set top border style and color
Border border = style.Borders.GetAt(BorderType.TopBorder);
border.LineStyle = CellBorderType.Medium;
border.Color = Color.Red;

cell.Style = style;


Thank You Laurence.

Now the problem is how can I get the borders of the cell if this cell has no style? (because this file was previously designed using Microsoft Excel). I see the others style properties are set in CellFormat of the cell, but borders is not in CellFormat.

Thank You.


Dear Alejandro,

Even the cell has no style in designer file, you can still use the sample code I gave you before. You can only set borders using Cell.Style.


Ok, I understand you, if I want to set borders I need to use Cell.Style.

The problem I tryed to describe in previous notes posted to this forum was:

If at designed file a cell has a border, later at runtime (after load that file) if I want to set a style with font, colors and alignment, but without change the border properties, how can I do that?

I understand I must to set borders properties usign the Cell.Style I am assigning to this cell, the problem I found was there is no way to access the borders set at designed file because the cell has Style=Nothing when I load this file using Aspose.Excel, and the CellFormat hasn’t borders properties. At runtime I don’t know what type of line style was used for the border!

Is there a way to access to the line style of the borders set at designed time in order to set the same to the new Cell.Style ???

Thank You in advance


Dear Alejandro,

I also understand your problem now. Currently, you cannot access the style of a cell in the designer file through API. The style of a cell in the designer file can only be saved to the result file or be replaced by Aspose.Excel API.