How to Add Cell Fill in Excel

[*-)]What’s Cell Fill in Excel?Cell fill is indeed the colors and patterns of the cell. The content in the cell could have many kinds of colors and patterns. It will be better to get good colors and patterns. The cell fill could give Excel a good appearance. And in fact there are three ways: you can choose the color; you can choose the pattern; you can choose both of them. The better choice will make Excel look better and have good impressions for others.

How to Add Cell Fill in Microsoft Excel?[:)]It is easy to add cell fill to Excel with Microsoft Excel. Once you have entered the content to the cell. You can select the format on the menu. Then select cellpattern. And now you can find there are many kinds of colors and patterns on the diaglog box. You can choose the colors and patterns which you need for your cell.

[H]Add Cell Fill via Spire.XLS.In Spire.XLS, you can use sheet.Range[“A1”].Style.Color method to set the color of the cell. While using sheet.Range[“A1”].Style.FillPattern, you can set the filled pattern of the cell. I will show you the way of cell fill below. In the end of the code, I give you the example of setting the color and pattern filled together.

The following code is about C# cell fill:

[C#]

using System.Drawing;
using Spire.Xls;

namespace Hyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new workbook.
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            
            //Write a common text.
            sheet.Range["B2"].Text = "Home page";
            
            //Write a text with background color.
            sheet.Range["B4"].Text = "Home page";
            sheet.Range["B4"].Style.Color = Color.Green;
            
            //Write a text to the cell with pattern filled in. 
            sheet.Range["B6"].Text = "Home page";
            sheet.Range["B6"].Style.FillPattern = ExcelPatternType.Percent125Gray;
            
            //Write a text with background color and pattern filled in.
            sheet.Range["B8"].Text = "Home page";
            sheet.Range["B8"].Style.Color = Color.Green;
            sheet.Range["B8"].Style.FillPattern = ExcelPatternType.Percent125Gray;
            sheet.AutoFitColumn(2);
            
            //Save the file.
            workbook.SaveToFile("Sample.xls");
            
            //Launch the file.
            System.Diagnostics.Process.Start("Sample.xls");
        }
    }
}
          

The following code is about VB.NET cell fill:

[Visual Basic]

Imports Microsoft.VisualBasic
Imports System.Drawing
Imports Spire.Xls

Module Module1

    Sub Main()
        'Create a new workbook.
        Dim workbook As Workbook = New Workbook()
        Dim sheet As Worksheet = workbook.Worksheets(0)
        
        'Write a common text.
        sheet.Range["B2"].Text = "Home page";
        
        'Write a text with background color.
        sheet.Range["B4"].Text = "Home page";
        sheet.Range["B4"].Style.Color = Color.Green;
        
        'Write a text to the cell with pattern filled in. 
        sheet.Range["B6"].Text = "Home page";
        sheet.Range["B6"].Style.FillPattern = ExcelPatternType.Percent125Gray;
        
        'Write a text with background color and pattern filled in.
        sheet.Range["B8"].Text = "Home page";
        sheet.Range["B8"].Style.Color = Color.Green;
        sheet.Range["B8"].Style.FillPattern = ExcelPatternType.Percent125Gray;
        sheet.AutoFitColumn(2);
        
        'Save the file.
        workbook.SaveToFile("Sample.xls")
        
        'Launch the file.
        System.Diagnostics.Process.Start("Sample.xls")
    End Sub
End Module