Free Support Forum -

Select all cells in an Excel worksheet to set a style/formatting in .NET

how can I select all cells in a worksheet to set a particuler style/font ?




See the sample code below for your reference:

Sample code:

Workbook wrkBook = new Workbook();
Worksheet sheet1 = wrkBook.Worksheets[0];
Cells cells = sheet1.Cells;
Style fontStyle = new Style();
Style style = new Style();
Aspose.Cells.Style stylefont = wrkBook.Styles[wrkBook.Styles.Add()];
stylefont.Font.Name = “Arial”;
stylefont.Font.Size = 9;
StyleFlag flag = new StyleFlag();
flag.FontName = true;
flag.FontSize = true;
cells.ApplyStyle(stylefont, flag);


Also, similarly, you may create a range and use Range.ApplyStyle(style, styleFlag) for your needs.

Thank you.

thnaks for reply,

do you have a specific example, to select all cells of worksheet?



Please see my sample code in previous post that set the default font (Arial, 12) to all the cells in the worksheet.
And, I am afraid, Aspose.Cells does not provide any relevant interface or events to select all the select (if you want this only), you have to do it by yourself opening the file into MS Excel.

Thank you.


what i want is select all cells in a worksheet, as I do in Microsoft Excel clicking the button on top-left corner as I attached


If you want to automate the Ms-Excel, then you should use VSTO tools and VBA.

If you want to select the cells and set their styles/fonts without the need of Ms-Excel programmatically, then use the code as shared earlier.

In order to select all cells, you will have to create a range spanning all the cells.

OK, many thanks


Thanks for your posting and using Aspose.Cells.

It’s good to know that you can devise a workaround to select all cells.

Also, we will introduce some constant numbers to let the user know about the Maximum Rows and Columns Limitation for Xls and Xlsx format.

We have therefore logged a new feature request for this issue in our database with the issue id: CELLSNET-41214.

Once, we will have some update for you, we will let you know asap.