Find and Highlight Data in Excel in C#, VB.NET

Find function in Excel enables developers/programmers to find appointed data in Excel worksheet, and highlight function makes the data founded more observably. Find and highlight function gives developers and programmers more convenience of analyzing the data. This section demonstrates a clear introduction of find and highlight data in Excel worksheet via a .NET Excel component with C#, VB.NET.

Spire.XLS for .NET, as a .NET Excel component, enables users to quickly and easily find and highlight data in excel file. By calling Worksheet class method: public CellRange[] FindAllNumber(double doubleValue, bool formulaValue), users can find a certain value in cell range and then, highlight the value by setting the style property CellRange.Style.Color.

Please download Spire.XLS for .NET and install it on your system, add Spire.XLS.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll". And then, preview the effect of find and highlight task as below picture:


Find and Highlight Excel Data

using Spire.Xls;

namespace fandh
    class Program
        static void Main(string[] args)
            //load an excel file from system
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\my file\FandH.xlsx", ExcelVersion.Version2010);

            //find and highlight excel data
            Worksheet sheet = workbook.Worksheets[0];
            foreach (CellRange range in sheet.FindAllNumber(1502,true))
                range.Style.Color = Color.LawnGreen;
            //save and launch the project
            workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);

Imports Spire.Xls

Namespace fandh
    Class Program
        Private Shared Sub Main(ByVal args() As String)
            'load an excel file from system
            Dim workbook As Workbook = New Workbook
            workbook.LoadFromFile("D:\my file\FandH.xlsx", ExcelVersion.Version2010)
            'find and highlight excel data
            Dim sheet As Worksheet = workbook.Worksheets(0)
            For Each range As CellRange In sheet.FindAllNumber(1502, true)
                range.Style.Color = Color.LawnGreen
            'save and launch the project
            workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010)
        End Sub
    End Class
End Namespace