When I use Microsoft Word to write an article or paper, I would like to set the font style, for example, setting characters size, color and so on. Generally, I will make the title be larger than other part or give the keywords a specified color to make it be obvious. As the same, we also need to set Excel font for the formatted Excel file can show others a beautiful report or make the important information be easy to be found.

When we open an Excel and then we can find that there are lots of button which can be used to set font style. We only need to click these buttons and select the wanted font style. It is very simple. However, developers usually need to operate Excel in C# to achieve customers’ requirements. How should we do to set Excel Font by C#?

In Excel, every data is imported into a cell. Therefore, the font setting can be called cell formatting. We can define the color, size or styles for the cell which is filled with characters or numbers. Now, I want to introduce a method to set Excel Font by using C#.Net when the cell type is Numeric.

Set the background color

objectSheet.get_Range(objectSheet.Cells[RowIndex,ColumnIndex],objectSheet.Cells[RowIndex,ColumnIndex]).Cells.Interior.Color =Color;

Set font color

objectSheet.get_Range(objectSheet.Cells[RowIndex,ColumnIndex],objectSheet.Cells[RowIndex,ColumnIndex]).Font.Color = Color;

Set font size

objectSheet.get_Range(objectSheet.Cells[RowIndex,ColumnIndex],objectSheet.Cells[RowIndex,ColumnIndex]).Font.Size = Size;

Besides, there are other methods to set Excel font, for example, using some middleware to complete formatting quickly. Recently, I found one kind of middleware which is called Spire.XLS. It used C# and VB.Net technology to complete Excel automation. It shows several demos about its detailed functions. In the Font Style demo, it shows us how to use C# and VB.Net to set Excel font style.