Style for a range of cells

Hello ,

I’ m trying to change the backgroundcolor of a range of cells. But if I create a new style, it also changes the font and formating. Is it possible to define that the style doesn’t affect font ( like in Excel) ? Another solution would be if I predefine a custom style in Excel, and use that style on the range. But I can’t get a reference to the predefined styles in de designerfile.
I know I can change the background for every cell in the range ( changing them one by one), but one of the above solutions would be much nicer.

Luc

Hi Luc,

Aspose.Excel object model has some diffrences with MS Excel. Range.Style is used to set same style to a whole range with same formatting(without caring the different settings). It's much faster.

In your case, you can set one by one. This approach retains previous settings but is slower.

Actually if I provide a range setting method as your wish, I also set them one by one.

Hello Laurence,

thanks for your fast reply. Not the best solution changing them one by one, but I get a workaround, so no big problem.
In the meantime I get 2 others questions : I noticed yesterday ( after posting this message) that the indent of cells get lost. And I mean cells with just text that aren’t changed by code. Strange 'cause everything else seems to be preserved perfect. Is it a big problem to solve this , because we use quite a lot of indents in our designer file ? ( not very urgent, would be enough if I know you’re working on it ).
And problem 2 : on opening in MS Excel a by code processed file, I always get the message 'Name conflict - name can not be the same as built-in name. Old name : print_area '. Which forces to input any name. I guess and hope it’s something from the evaluation version ?


If priorities don’t change again I really start implementing charts today (cfr. my question a few weeks ago. Quick test looked ok ). I hope I won’t come in problems, 'cause that’s really important to us. But so far Aspose Ecel seems to be the tool we’re looking for … Yes

Luc

Hi Luc,

Which version are you using? We have found and fixed these two problems in old versions. Please download the latest version at



If the problem still occurs, please upload your sample code and template file here. I will check them ASAP.

Hi Laurence,

I am running into a problem by setup the format one by one. I just posted my thread. Is there any other way I can make the format working without a “TOO many different cell format”?

thank you

Which version are you using? We have already fixed this bug in the latest version. Please download it at

@LucSimarch,
Aspose.Excel is discarded now and no more under active development now. It is replaced by Aspose.Cells that is much advanced and better in performance as compared to its predecessor. You can set a specific style on a range of cells without changing other different styles present in cells in the range with a single command. It does not require setting style for each cell individually. Here is a code snippet that demonstrates this feature where only the background of all cells in a range is updated without affecting other styles of cells.

Workbook workbook = new Workbook("Book1.xlsx");
Cells cells = workbook.Worksheets[0].Cells;

// Create a range (A1:C2).
Range range = cells.CreateRange("A1", "C2");

// Create a style object.
Style style = workbook.CreateStyle();

// Specify the shading color.
style.ForegroundColor = Color.Yellow;
style.Pattern = BackgroundType.Solid;

// Create the styleflag object.
StyleFlag flag = new StyleFlag();
// Implement the shading / fill color.
flag.CellShading = true;

// Set the Range style.
range.ApplyStyle(style, flag);

workbook.Save("output.xlsx");

Input File

Output File

For more information on working with styles for a range, refer to the following artilce:
Format and Modify Named Ranges

For trial purpose, download the latest version here:
Aspose.Cells for .NET (Latest Version)

Download a readily runnable example projects here to test different features of this product.